{ "info": { "author": "HubSpot Developer", "author_email": "devteam+hscacheutils@hubspot.com", "bugtrack_url": null, "classifiers": [], "description": "[![Build Status](https://travis-ci.org/HubSpot/hscacheutils.png?branch=master)](https://travis-ci.org/HubSpot/hscacheutils)\n\nA python implementation of [generational caching](http://www.regexprn.com/2011/06/web-application-caching-strategies_05.html).\n\nThree main interfaces are provided:\n\n - Direct methods `gen_cache.get`, `gen_cache.set`, `gen_cache.invalidate`, and `gen_cache.delete`\n - A `CustomUseGenCache` instance\n - A function decorator `@gen_cache.wrap`\n\n\n## Direct methods:\n\n```python\nfrom hscacheutils.generational_cache import gen_cache\n\nhtml = gen_cache.get(('nav', 'nav_portal:user_id'), user_id=1)\ngen_cache.set('', ('nav', 'nav_portal:user_id'), user_id=1)\ngen_cache.invalidate(('nav', 'nav_portal:user_id'), user_id=1)\n```\n\n## A `CustomUseGenCache` instance\n\nThe same as the direct methods, but creates an object so that you con't have to keep on passing in the generation names every single time.\n\n```python\ncustom_cache = CustomUseGenCache([\n 'customgenz:user_id',\n 'customgenz:blog_id'\n])\n\nblog_id = 17\nuser_id = 123\nkey = random.randint(1, 20000000)\n\nval = custom_cache.get(blog_id=blog_id, user_id=123, cache_key=key)\ncustom_cache.set(value=first_val, blog_id=blog_id, user_id=123, cache_key=key)\ncustom_cache.invalidate(user_id=123)\ncustom_cache.delete(blog_id=blog_id, user_id=123, cache_key=key)\n```\n\n\n## The `@gen_cache.wrap` decorator\n\nIt can be applied to function, method or classmethod. It is mostly similar to gen_cache.get, but with some additional magic to make your life easier.\n\n\n### Magic #1: (true for all 3 interfaces)\n\nThe contents of \"value-based\" generations are automatically pulled from the arguments in wrapped function. Eg.\n\n```python\n@gen_cache.wrap('project_name', 'foo_per_user_id:user_id')\ndef foobar(user_id):\n ...\n\nfoobar(53) # Uses 'project_name' and 'foo_per_user_id:53' as generations\nfoobar(999) # Uses 'project_name' and 'foo_per_user_id:999' as generations\n\n# So when invalidating like so...\ngen_cache.invalidate(\"for_per_user_id:user_id\", user_id=999)\n\nfoobar(53) # This is still cached\nfoobar(999) # This has been invalidated\n```\n\nSo the when foobar is called the ':user_id' part of the value-based generation looks for any\nargument named \"user_id\", then takes its value to create a generation such as \"for_per_user_id:53\".\nThis means that the \"for_per_user_id\" generation is only invalidated on a per-portal basis\n\n\n### Magic #2: (true for all 3 interfaces)\n\nAll of the arguments (not used in value-based generations described above) are automatically appended to the cache key. Eg.\n\n```python\n@gen_cache.wrap('whatever')\ndef foobar(something, another=False):\n ...\n\n# XXX represents the current counter value of the 'whatever' generation\n\nfoobar(1) # Uses a cache key roughly like: \"whatever:XXX [1]{another=False}\"\nfoobar(2) # Uses a cache key roughly like: \"whatever:XXX [2]{another=False}\"\nfoobar(2, another=True) # Uses a cache key roughly like: \"whatever:XXX [2]{another=True}\"\n\n# So when invalidating like so...\ngen_cache.invalidate(\"whatever\")\n\nfoobar(1) # This has been invalidated\nfoobar(2) # This has been invalidated\nfoobar(2, another=True) # This has been invalidated\n```\n\nIf you don't what this behavior for one or more arguments, make sure to put the name of that\nargument(s) in the \"exclude\" option (see below).\n\n\n### Magic #3: (only true for the decorator)\n\nThe cache key will automatically include the current module name, function name, and\nline number. So when this function moves to a different file, is renamed, or moves up or down a\nfew lines, the cache will automatically be invalidated.\n\n(Note, I'm not sure this file/function name magic is worth keeping)\n\n### EXTRAS\n\nThe wrapped callable gets `invalidate` methods. Call `invalidate` with\nsame arguments as function and the result for these arguments will be\ninvalidated.\n\n### KEYWORD OPTIONS\n\ntimeout=3600 (defaults to None) is the number of seconds before this cache should expire\n\nexclude=[...] (defaults to empty list) is all the arguments you do not want to automaticaaly be\na included in the cache key.\n\nlog_misses=True (False by default) will print out some debugging into on every cache miss\n\nignore_locally=True (False by default) will disable this caching when ENV == 'local'\n\n### REAL `gen_cache.wraps` cache key example\n\n [cached]hsdjango.test.test_generational_cache.func_with_lots_of_args:369(['one','two']{'project':1336056824437339,'foobar':'NOThello','user_id':42})\n ^ ^ ^ ^ ^ ^ ^\n | | | | | | |\n prefix module name func name line # | generation & current counter value |\n | |\n non-excluded positional args non-excluded keyword args\n\n\n\n\nGotcha #1: Be careful to use either \"self\" or \"cls\" as the first argument name when wrapping\nmethods and classmethods. This code relies on those names (see _func_type) to automatically\nchop off the first argument from the cache key.\n\n\n\n_Note: based on (and built re-using) django-cache-utils._", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://dev.hubspot.com/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "hscacheutils", "package_url": "https://pypi.org/project/hscacheutils/", "platform": "any", "project_url": "https://pypi.org/project/hscacheutils/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://dev.hubspot.com/" }, "release_url": "https://pypi.org/project/hscacheutils/0.1.8/", "requires_dist": null, "requires_python": null, "summary": "Some of Hubspot's python cache utils, namely generational caching", "version": "0.1.8" }, "last_serial": 1094584, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "aeed4550b6b6818c313166cde20120e7", "sha256": "a6d05196edabb87c5da409fd2a982941e9c861d4fc7acbf620f4010b6a5479d8" }, "downloads": -1, "filename": "hscacheutils-0.1.1.tar.gz", "has_sig": false, "md5_digest": "aeed4550b6b6818c313166cde20120e7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9437, "upload_time": "2013-03-04T14:30:26", "url": "https://files.pythonhosted.org/packages/ff/fe/6461ef8431c86c2ed32cfacdf06059a4a2b3d417c03cb140609abc7ade8f/hscacheutils-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "5365da32782c4bf37640e5dd4c19a5e4", "sha256": "6bcf8aab7c6bb4942b879b897a565843c6fac85fef928f8c531ff767feab6a5c" }, "downloads": -1, "filename": "hscacheutils-0.1.2.tar.gz", "has_sig": false, "md5_digest": "5365da32782c4bf37640e5dd4c19a5e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9885, "upload_time": "2013-03-04T14:41:28", "url": "https://files.pythonhosted.org/packages/d1/89/d1ea5e57be1c9faaa256f53676a4f53eb435e314cffe6b1478497c8916b9/hscacheutils-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "6b092bf49d8259a28cf93261a31b6e24", "sha256": "4252ac974adc0d36564f1366e2664f7ebe1be9c4ebad6ab854170538daf16c05" }, "downloads": -1, "filename": "hscacheutils-0.1.3.tar.gz", "has_sig": false, "md5_digest": "6b092bf49d8259a28cf93261a31b6e24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9947, "upload_time": "2013-03-04T15:11:35", "url": "https://files.pythonhosted.org/packages/eb/4e/e04b8f319208a352e39a9004adef2bd18afb7af84e3c75f59767386a7fb7/hscacheutils-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "e303c4e8d731c2f94e75c93c09cb97de", "sha256": "7a91cd0d81accacfbf74ad94135b6158068ed0a6e1670eaea503d471c92a123d" }, "downloads": -1, "filename": "hscacheutils-0.1.4.tar.gz", "has_sig": false, "md5_digest": "e303c4e8d731c2f94e75c93c09cb97de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10033, "upload_time": "2013-03-04T15:29:30", "url": "https://files.pythonhosted.org/packages/83/c4/c4a982760382838eaf1fea3478f96dea53743a52a6efd56c723f67b5f4b4/hscacheutils-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "a124086fdf589bac0e6df3581db49bdc", "sha256": "157c568cb11ff287cb3c1dcb4ff5567e0d14fb905a1139b41c3bd0e33d65914a" }, "downloads": -1, "filename": "hscacheutils-0.1.5.tar.gz", "has_sig": false, "md5_digest": "a124086fdf589bac0e6df3581db49bdc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10091, "upload_time": "2013-03-05T18:35:52", "url": "https://files.pythonhosted.org/packages/44/c3/2098cbeb9cccdc0278915460a083c50210e5b4569d0203bd1e93878ee701/hscacheutils-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "a79d283e58e6645003d6f1cad035288a", "sha256": "9897548d7bc0ea982abd51ff71bbb11890cfe7a2e50b613665fac7a3d6e87cef" }, "downloads": -1, "filename": "hscacheutils-0.1.6.tar.gz", "has_sig": false, "md5_digest": "a79d283e58e6645003d6f1cad035288a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10098, "upload_time": "2013-07-08T19:56:19", "url": "https://files.pythonhosted.org/packages/00/20/e91bc068f6687aaac09f4c0f3f630c9c33fe19feeecad249b45775b18c28/hscacheutils-0.1.6.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "6d2a5d0e4a5816184c03b7ba6931d00d", "sha256": "4ad2e24b5672e05255f217867e627f9f010b3fe36556ea1a7c524f2d070364dc" }, "downloads": -1, "filename": "hscacheutils-0.1.8.tar.gz", "has_sig": false, "md5_digest": "6d2a5d0e4a5816184c03b7ba6931d00d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10138, "upload_time": "2014-05-16T13:47:24", "url": "https://files.pythonhosted.org/packages/4c/d4/3ba0166909a753dcbcce8277e1e298a9953c1722dbbab39d713f0d96bb71/hscacheutils-0.1.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6d2a5d0e4a5816184c03b7ba6931d00d", "sha256": "4ad2e24b5672e05255f217867e627f9f010b3fe36556ea1a7c524f2d070364dc" }, "downloads": -1, "filename": "hscacheutils-0.1.8.tar.gz", "has_sig": false, "md5_digest": "6d2a5d0e4a5816184c03b7ba6931d00d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10138, "upload_time": "2014-05-16T13:47:24", "url": "https://files.pythonhosted.org/packages/4c/d4/3ba0166909a753dcbcce8277e1e298a9953c1722dbbab39d713f0d96bb71/hscacheutils-0.1.8.tar.gz" } ] }