{"id":43141295,"url":"https://github.com/huangjunwen/tagcache","last_synced_at":"2026-01-31T22:39:59.145Z","repository":{"id":57473189,"uuid":"88315807","full_name":"huangjunwen/tagcache","owner":"huangjunwen","description":"A small file-based cache library with tag support.","archived":false,"fork":false,"pushed_at":"2017-04-20T07:46:56.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-06T23:46:41.648Z","etag":null,"topics":["cache","file-system","python-library","tags"],"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/huangjunwen.png","metadata":{"files":{"readme":"README.md","changelog":"Change.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-15T01:37:07.000Z","updated_at":"2017-04-17T12:09:39.000Z","dependencies_parsed_at":"2022-09-26T16:31:03.889Z","dependency_job_id":null,"html_url":"https://github.com/huangjunwen/tagcache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/huangjunwen/tagcache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangjunwen%2Ftagcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangjunwen%2Ftagcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangjunwen%2Ftagcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangjunwen%2Ftagcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huangjunwen","download_url":"https://codeload.github.com/huangjunwen/tagcache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangjunwen%2Ftagcache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28958348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T22:20:19.638Z","status":"ssl_error","status_checked_at":"2026-01-31T22:18:07.061Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","file-system","python-library","tags"],"created_at":"2026-01-31T22:39:55.233Z","updated_at":"2026-01-31T22:39:59.139Z","avatar_url":"https://github.com/huangjunwen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TagCache\n\n## Support platform\n\n- linux\n- macos\n\n## How to install\n\n```base\n$ pip install tagcache\n```\n\n## Example usage\n\nSuppose you have a blog. And want to cache blog pages (e.g. home page).\n\n- First you need to create and configure a `Cache` object.\n\n```python\nfrom tagcache import Cache, NotCache\n\ncache = Cache()\n\n# configure the main directory to store cache files\ncache.configure('/tmp/blog_cache')\n\n```\n\n- Decorate the content function with the `Cache` object. In the following example\n  - `blog-home` is the key name of the cache\n  - `expire` specify the expiration in seconds of the cache (7 days), never expire if omitted\n  - `blog-new` and `bio` are the tags of the cache\n  - finally call the decorated function to get content, the function will use cache or call the original function to generate new content when cache miss\n\n```python\n\n@cache('blog-home', expire=3600*24*7, tags=('blog-new', 'bio'))\ndef home_page_content(cache_param):\n\n    ...\n    # sometimes content is not available and you don't want\n    # to cache the return value.\n    cache_param.disable()\n\n    # sometimes tags are only known at runtime\n    cache_param.tags.add('some-more-tag')\n\n    # sometimes you want to change expire\n    cache_param.expire = 3600*24\n\n    # generate home page content ...\n    ...\n    return {\"bio\": {...}, \"recent_blogs\": [...]}\n\ncontent = home_page_content()\n```\n\n- Later, you make changes to your bio (which is displayed on home page), then you can invalidate all caches containing the bio\n\n```python\ncache.invalidate_tag(\"bio\")\n```\n\n- Periodically, you need to clean up those expired or invalid files.\n\n```python\ncache.cleanup()\n```\n\n## How it works\n\nThe cache directory looks like:\n\n```bash\n.\n├── data\n│   ├── 18\n│   │   └── ae\n│   │       └── tag:62696f                  \u003c-- tag directory: hexlify('bio')\n│   │           └── 85\n│   │               └── 3:110235185         \u003c-- hardlink of 'key:626c6f672d686f6d65'\n│   ├── 37\n│   │   └── 64\n│   │       └── tag:626c6f672d6e6577        \u003c-- tag directory: hexlify('blog-new')\n│   │           └── 85\n│   │               └── 3:110235185         \u003c-- hardlink of 'key:626c6f672d686f6d65'\n│   └── ae\n│       └── 08\n│           └── key:626c6f672d686f6d65      \u003c-- cache file: hexlify('blog-home')\n└── tmp\n```\n\nLoad process:\n\n1. Try to open exists cache file: `\"key:\" + hexlify(key)`\n1. If not found, generate content (see below)\n1. If found, check expiration (`st_mtime` as expire time) and tags validation (`st_nlink`)\n    1. If all checks were passed, return the cache directly\n    1. Try to flock the cache file in non-blocking mode, generate content if success, return cache otherwise\n\n\nGenerate content process:\n\n1. Create a temporary file under tmp and save serialized content (with tags info as well)\n1. Hardlink the temporary file into tag directories (`nlinks + inode number` as link name)\n1. Change the `mtime` of the temporary file to the expire time\n1. Atomic move (rename) the temporary file to the final destination: `\"key:\" + hexlify(key)`\n\nInvalidate tag process: just remove the tag directory\n\n## Author\n\nHuang junwen (email: \u003ckassarar@gmail.com\u003e)\n\n## Licence\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangjunwen%2Ftagcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuangjunwen%2Ftagcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangjunwen%2Ftagcache/lists"}