{"id":27453794,"url":"https://github.com/fraserchapman/script.module.cache","last_synced_at":"2025-07-10T07:03:49.461Z","repository":{"id":54769775,"uuid":"194259462","full_name":"FraserChapman/script.module.cache","owner":"FraserChapman","description":"Kodi HTTP cache module using sqlite3 ","archived":false,"fork":false,"pushed_at":"2024-07-20T20:51:01.000Z","size":16,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-05T14:36:54.062Z","etag":null,"topics":["cache","kodi","kodi-module"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FraserChapman.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-06-28T11:03:36.000Z","updated_at":"2024-09-25T09:26:23.000Z","dependencies_parsed_at":"2025-04-15T13:57:16.717Z","dependency_job_id":"87e1d420-43aa-4e46-b4d1-20dbdffb9c8f","html_url":"https://github.com/FraserChapman/script.module.cache","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/FraserChapman/script.module.cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FraserChapman%2Fscript.module.cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FraserChapman%2Fscript.module.cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FraserChapman%2Fscript.module.cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FraserChapman%2Fscript.module.cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FraserChapman","download_url":"https://codeload.github.com/FraserChapman/script.module.cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FraserChapman%2Fscript.module.cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264543539,"owners_count":23625385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","kodi","kodi-module"],"created_at":"2025-04-15T13:57:11.199Z","updated_at":"2025-07-10T07:03:49.455Z","avatar_url":"https://github.com/FraserChapman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# script.module.cache\n\n![foo](resources/icon.png)\n\nSimple Python HTTP Cache using sqlite3\n\n*   Stores cached data in sqlite3.Blobs.\n*   Calculates lifetime, freshness as virtual columns.\n*   Obeys cache control directives, immutable, no-store, etc.\n*   Supports etag, last_modified, etc for conditional requests.\n*   Can be used as a generic key/blob data store when used without directives.\n\nBy default the Cache (and Store) use a sqlite3 database named \"cache.sqlite\" located in the add-on profile directory\n\n## Examples\n\nQuick examples of basic usage \n\n## Request cache\n\nHow to use the Cache class with requests\n\nThe Cache class allows you to easily store URIs, as keys, along with their response data and headers in a persistent database.\n\nThe calculated column \"fresh\" and the \"conditional_headers\" method can be used to limit the number of requests made\nand the amount of data transferred respectively.\n \n~~~~python\nimport requests\nfrom cache import Cache, conditional_headers\n \n  \ndef get_html(uri):\n    # type: (str) -\u003e Union[str, None]\n    headers = {\n        \"Accept\": \"text/html\",\n        \"Accept-encoding\": \"gzip\"\n    }\n    with Cache() as c:\n        # check if uri is cached\n        cached = c.get(uri)\n        if cached:\n            # if the data is fresh then simply return it\n            if cached[\"fresh\"]:\n                return cached[\"blob\"]\n            # otherwise append applicable \"If-None-Match\"/\"If-Modified-Since\" headers\n            headers.update(conditional_headers(cached))\n        # request a new version of the data\n        r = requests.get(uri, headers=headers, timeout=60)\n        if 200 == r.status_code:\n            # add the new data and headers to the cache \n            c.set(uri, r.content, r.headers)\n            return r.content\n        if 304 == r.status_code:\n            # the data hasn't been modified so just touch the cache with the new headers\n            # and return the existing data\n            c.touch(uri, r.headers)\n            return cached[\"blob\"]\n        # perhaps log any other status codes for debugging\n        return None\n \n~~~~\n\n## Generic string storage\n\nGeneric string storage is facilitated by the Store class.\n\nThe Store class allows a \"key\" to be used to append to, remove from or retrieve a set of unique string values.\n\nThis is useful for saving things like; a history of searched terms, urls of played films, etc.\n\n~~~~python\nfrom cache import Store\n \n \n# key can be anything, app:// prefix isn't required\n# the only requirement is that the key be unique with in your add-on\nsearches = Store(\"app://user-searches\") \n \n# add strings to the store\nsearches.append(\"foo\")\nsearches.append(\"bar\")\nsearches.append(\"bat\")\nprint(searches.retrieve())  # {'bar', 'bat', 'foo'}\n \n# remove a string from the store\nsearches.remove(\"bar\")  \nprint(searches.retrieve())  # {'bat', 'foo'}\n  \n# clear the store\nsearches.clear()\nprint(searches.retrieve())  # set()\n \n~~~~\n\n## References \n\n*   [DB-API 2.0 interface for SQLite databases](https://docs.python.org/2/library/sqlite3.html)\n*   [RFC7234 - HTTP/1.1 Caching](https://tools.ietf.org/html/rfc7234)\n*   [RFC7232 - HTTP/1.1 Conditional Requests](https://tools.ietf.org/html/rfc7232)\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/26afc2828d1e439eafd563967a391f5b)](https://www.codacy.com/app/FraserChapman/script.module.cache?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=FraserChapman/script.module.cache\u0026amp;utm_campaign=Badge_Grade)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraserchapman%2Fscript.module.cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffraserchapman%2Fscript.module.cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraserchapman%2Fscript.module.cache/lists"}