{ "info": { "author": "Huang Junwen", "author_email": "kassarar@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries" ], "description": "# 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\u251c\u2500\u2500 data\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 18\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 ae\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 tag:62696f <-- tag directory: hexlify('bio')\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 85\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 3:110235185 <-- hardlink of 'key:626c6f672d686f6d65'\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 37\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 64\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 tag:626c6f672d6e6577 <-- tag directory: hexlify('blog-new')\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 85\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 3:110235185 <-- hardlink of 'key:626c6f672d686f6d65'\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 ae\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 08\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 key:626c6f672d686f6d65 <-- cache file: hexlify('blog-home')\n\u2514\u2500\u2500 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: )\n\n## Licence\n\nMIT\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/huangjunwen/tagcache", "keywords": "python cache tag file-based", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "TagCache", "package_url": "https://pypi.org/project/TagCache/", "platform": "", "project_url": "https://pypi.org/project/TagCache/", "project_urls": { "Homepage": "https://github.com/huangjunwen/tagcache" }, "release_url": "https://pypi.org/project/TagCache/0.2.2/", "requires_dist": null, "requires_python": "", "summary": "A small file-based cache library with tag support.", "version": "0.2.2" }, "last_serial": 2816308, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "6af693bfb54e31f998aae404442e8a85", "sha256": "9a7b72d97b94001f3cc5786e03facd91c163a9f79cd9c47f9363ca22d787c410" }, "downloads": -1, "filename": "TagCache-0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "6af693bfb54e31f998aae404442e8a85", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10004, "upload_time": "2017-04-19T01:18:12", "url": "https://files.pythonhosted.org/packages/0a/56/4e7f544c9e37427e41646fe12b0f302f8ff3b0b1bee868b3b7451b760d9b/TagCache-0.2-py2-none-any.whl" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f5681c20654184ae4aa7bad1fadf7f15", "sha256": "c8bc56156bd72807085b5543511c6a49a2653da07057eed51ce47e1a947a7a6c" }, "downloads": -1, "filename": "TagCache-0.2.1-py2-none-any.whl", "has_sig": false, "md5_digest": "f5681c20654184ae4aa7bad1fadf7f15", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10298, "upload_time": "2017-04-19T07:20:11", "url": "https://files.pythonhosted.org/packages/79/8e/e5cc4b4611a7ab849e12b160afcd387902991be8479da441848bf27b52ee/TagCache-0.2.1-py2-none-any.whl" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "85a9e3e4b0d00f619d5d502e6622fd58", "sha256": "d39345626480968834ec5d025224b58e86e55c7b571cf1808092705fe9c1499d" }, "downloads": -1, "filename": "TagCache-0.2.2-py2-none-any.whl", "has_sig": false, "md5_digest": "85a9e3e4b0d00f619d5d502e6622fd58", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10406, "upload_time": "2017-04-20T07:48:37", "url": "https://files.pythonhosted.org/packages/d2/b6/47bf272065bbfc70531c2d7e5435d90c34a568afa7507485d254686133ba/TagCache-0.2.2-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "85a9e3e4b0d00f619d5d502e6622fd58", "sha256": "d39345626480968834ec5d025224b58e86e55c7b571cf1808092705fe9c1499d" }, "downloads": -1, "filename": "TagCache-0.2.2-py2-none-any.whl", "has_sig": false, "md5_digest": "85a9e3e4b0d00f619d5d502e6622fd58", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10406, "upload_time": "2017-04-20T07:48:37", "url": "https://files.pythonhosted.org/packages/d2/b6/47bf272065bbfc70531c2d7e5435d90c34a568afa7507485d254686133ba/TagCache-0.2.2-py2-none-any.whl" } ] }