{ "info": { "author": "Simon Kaeser", "author_email": "skaeser@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python" ], "description": "Introduction\n============\n\nThe ``horae.cache`` package provides simple decorators for caching. There are decorators\navailable for caching vocabularies (contextual or global) and for caching method and\nfunction output on the request.\n\nUsage\n=====\n\nVocabulary\n----------\n\nThere are three different ways to cache a vocabulary:\n\n**Global cache**\n Caches the vocabulary globally\n**Contextual cache**\n Caches the vocabulary in the given context\n**Contextual parent cache**\n Caches the vocabulary in the defined parent of the given context\n\nEvery type of cache has a corresponding invalidation function to clear the cache for\nthe given vocabulary. This is especially usable when using dynamic vocabularies which\nchange over time for example a vocabulary of content objects of a given type::\n\n import grok\n \n from zope.schema import vocabulary\n from some.module.interfaces import ISampleContent\n from horae.cache import vocabulary\n \n @vocabulary.cache_global\n def all_sample_contents(context):\n # find all content objects of type ISampleContent\n return vocab\n vocabulary.getVocabularyRegistry().register(\n 'allsamplecontents',\n all_sample_contents)\n \n @grok.subscribe(ISampleContent, grok.IObjectModifiedEvent)\n @grok.subscribe(ISampleContent, grok.IObjectMovedEvent)\n def invalidate_all_sample_contents_cache(obj, event):\n vocabulary.invalidate_global(all_sample_contents)\n\nThe contextual cache is used for context specific vocabularies and are used the same way\nas the global cache::\n\n @vocabulary.cache_contextual\n def sample_contents_in_context(context):\n # find all content objects of type ISampleContent\n # in the given context\n return vocab\n vocabulary.getVocabularyRegistry().register(\n 'samplecontentsincontext',\n sample_contents_in_context)\n \n @grok.subscribe(ISampleContent, grok.IObjectModifiedEvent)\n @grok.subscribe(ISampleContent, grok.IObjectMovedEvent)\n def invalidate_sample_contents_in_context_cache(obj, event):\n # iterate over all the parents of the object and call:\n vocabulary.invalidate_contextual(parent,\n sample_contents_in_context)\n\nThe contextual parent cache is used slightly different. It takes an optional interface as\na parameter to find the parent to cache the vocabulary on. The cache steps up the object\nhierarchy until it finds a parent implementing the given interface. If no interface is\ngiven the immediate parent of the vocabulary context is taken as the cache context. An\nexample usage may look like this::\n\n from some.module.interfaces import ISampleContainer\n\n @vocabulary.cache_contextual_parent(ISampleContainer)\n def sample_contents_in_parent_of_context(context):\n # find all content objects of type ISampleContent in\n # the first found parent implementing ISampleContainer\n # of the given context\n return vocab\n vocabulary.getVocabularyRegistry().register(\n 'samplecontentsinparentofcontext',\n sample_contents_in_parent_of_context)\n \n @grok.subscribe(ISampleContent, grok.IObjectModifiedEvent)\n @grok.subscribe(ISampleContent, grok.IObjectMovedEvent)\n def invalidate_sample_contents_in_context_cache(obj, event):\n vocabulary.invalidate_contextual_parent(\n obj,\n ISampleContainer,\n sample_contents_in_parent_of_context)\n\nRequest\n-------\n\nTo cache the output of a function for the current request simply add the\n``horae.cache.request.cache`` decorator::\n\n from horae.cache import request\n \n @request.cache()\n def some_heavy_computation(arg1, arg2, kwarg1=True, kwarg2=True):\n # do the heavy computation\n return result_of_the_heavy_computation\n\nThe ``horae.cache.request.cache`` takes two optional arguments ``args`` and ``kwargs``\nusing which one may define what arguments and/or keyword arguments are relevant for the\noutput. If in the example above the output would be the same if arg2 and kwarg2 was set\ndifferently the decorator could look like this to improve the caching::\n\n @request.cache(args=(0,), kwargs=('kwarg1',))\n def some_heavy_computation(arg1, arg2, kwarg1=True, kwarg2=True):\n # do the heavy computation\n return result_of_the_heavy_computation\n\nDependencies\n============\n\n* `plone.memoize `_\n* `grok `_\n\nChangelog\n=========\n\n1.0a1 (2012-01-16)\n------------------\n\n- Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "horae.cache", "package_url": "https://pypi.org/project/horae.cache/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/horae.cache/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/horae.cache/1.0a1/", "requires_dist": null, "requires_python": null, "summary": "Provides utilities and decorators for caching", "version": "1.0a1" }, "last_serial": 792986, "releases": { "1.0a1": [ { "comment_text": "", "digests": { "md5": "1649a0c3feeab9aa1f66da6107e3b4bc", "sha256": "7ef2daba084a7bd108a78aa0ac837ed71e4c9cabedc3fdc3b55f39651660ca50" }, "downloads": -1, "filename": "horae.cache-1.0a1.tar.gz", "has_sig": false, "md5_digest": "1649a0c3feeab9aa1f66da6107e3b4bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4970, "upload_time": "2012-01-16T12:00:59", "url": "https://files.pythonhosted.org/packages/fa/c2/b421fe6c8ca187c419098cdc543cdf6e65fa1a1ae293fe04dbbdb770996f/horae.cache-1.0a1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1649a0c3feeab9aa1f66da6107e3b4bc", "sha256": "7ef2daba084a7bd108a78aa0ac837ed71e4c9cabedc3fdc3b55f39651660ca50" }, "downloads": -1, "filename": "horae.cache-1.0a1.tar.gz", "has_sig": false, "md5_digest": "1649a0c3feeab9aa1f66da6107e3b4bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4970, "upload_time": "2012-01-16T12:00:59", "url": "https://files.pythonhosted.org/packages/fa/c2/b421fe6c8ca187c419098cdc543cdf6e65fa1a1ae293fe04dbbdb770996f/horae.cache-1.0a1.tar.gz" } ] }