{ "info": { "author": "Fairfax Media", "author_email": "opensource@pitcre.ws", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Calm Cache for Django\n\n`django-calm-cache` keeps your cache calm while your site is being hammered by\nbucket loads of traffic.\n\n## Key Features\n\n * [Mint caching](http://djangosnippets.org/snippets/155/) to avoid the\n [dog pile](http://en.wikipedia.org/wiki/Cache_stampede) effect\n * Timeout jitter to reduce the number of entries expiring simultaneously\n * Works alongside any other Django cache backend\n * `MemcachedCache` and `PyLibMCCache` Django backends are extended to support\n data compression provided by [python-memcached](ftp://ftp.tummy.com/pub/python-memcached/)\n and [pylibmc](http://sendapatch.se/projects/pylibmc/) respectively\n * `PyLibMCCache` is extended to support binary protocol\n * `cache_response` decorator that could be applied to any Django view and\n conditionally cache responses just like Django standard `CacheMiddleware`\n and `cache_page` do, but more configurable, explicit and extensible\n\n## Installation\n\n :::shell\n pip install hg+https://bitbucket.org/pitcrews/django-calm-cache/\n\n\n### Cache Backends\n\nUpdate the cache settings in your `settings.py`:\n\n :::python\n CACHES = {\n 'default': {\n 'BACKEND' : 'calm_cache.backends.CalmCache',\n 'LOCATION': 'locmem-cache',\n 'KEY_FUNCTION': 'calm_cache.contrib.sha1_key_func',\n 'OPTIONS': {\n 'MINT_PERIOD': '10', # Allow stale results for this many seconds. Default: 0 (Off)\n 'GRACE_PERIOD': '120', # Serve stale value once during this period. Default: 0 (Off)\n 'JITTER': '10', # Upper bound on the random jitter in seconds. Default: 0 (Off)\n },\n },\n 'locmem-cache': {\n 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',\n 'LOCATION': 'foo',\n },\n 'zipped-memcached': {\n 'BACKEND': 'calm_cache.backends.MemcachedCache',\n 'LOCATION': '127.0.0.1:11211',\n 'OPTIONS': {\n 'MIN_COMPRESS_LEN': 1024, # Compress values of this size or larger, bytes. Default: 0 (Disabled)\n },\n },\n 'zipped-bin-pylibmc': {\n 'BACKEND': 'calm_cache.backends.PyLibMCCache',\n 'LOCATION': '127.0.0.1:11211',\n 'OPTIONS': {\n 'MIN_COMPRESS_LEN': 1024, # Compress values of this size or larger, bytes. Default: 0 (Disabled)\n 'BINARY': True, # Enable binary protocol for this backend. Default: False (Disabled)\n },\n },\n }\n\nNow relax knowing your site's caching won't fall over at the first sign of sustained traffic.\n\n#### CalmCache Configuration\n\n\n`LOCATION` parameter defines the name of another, \"real\", Django cache backend\nwhich will be used to actually store values\n\n`CalmCache` backend accepts the following options:\n\n * `MINT_PERIOD`: the time period that starts right after the user-supplied\n or default timeout (`TIMEOUT` setting) ends.\n First request during this period receives get() miss (`None` or default) and\n refreshes the value while all other requests are returning cached (stale)\n value until it is either updated or expired. Seconds. Default: `0`\n * `GRACE_PERIOD`: the time period starting after mint delay.\n During grace period stale value is returned only once and is removed after that.\n Seconds. Default: `0`\n * `JITTER`: defines the range for `[0 ... JITTER]` random value\n that is added to client supplied and \"real\" cache timeouts. Seconds. Default: `0`\n\n\n#### CalmCache Guidelines\n\nActual stored key names are composed of `CalmCache.make_key()`\nand underlying cache's `make_key()` methods' outputs, and therefore are stacked:\n\n real_cache_prefix:calm_cache_prefix:user_supplied_key\n\n\nMinting is designed to cope with highly concurrent requests and good value\nof `MINT_PERIOD` would be comparable to the stored object regeneration time.\n\nGrace period starts after mint delay and first request that comes during this time\nis satisfied with stale value. The value cached under the given key\nis invalidated immediately and next requesting client will refresh and\nstore a new value. This technique improves hit ratio for infrequently accessed\ndata when occasional staleness is affordable.\n\nAdd random variability to the expiry of cache objects as they may be generated\nat the same time, which mitigates expiry synchronisation\n\nThe maximum real cache TTL is caclulated as\n\n timeout + MINT_PERIOD + GRACE_PERIOD + JITTER\n\n\nSetting `MINT_PERIOD`, `GRACE_PERIOD` or `JITTER` to `0` or not setting them\nat all turns off relevant logic in the code.\n\n\n#### CalmCache Limitations\n\n * `CalmCache` currently only supports cache methods `add`, `set`, `get`, `delete`,\n `has_key` and `clear`\n\n\n### Response Cache\n\nExample usage:\n\n :::python\n from calm_cache.decorators import cache_response\n\n @cache_response(15, key_prefix='my_view', codes=(200, 404))\n def my_view(request, slug=None):\n return HttpResponse()\n\n`cache_response`'s constructor arguments, relevant Django settings and\ndefaults:\n\n * `cache_timeout`: integer, default TTL for cached entries. Required\n * `cache`: Django cache backend name. If not specified, default cache\n backend will be used\n * `key_prefix`: this string is always prepending resulting keys.\n Default: `''`. Django setting: `CCRC_KEY_PREFIX`\n * `methods`: a list/tuple with request methods that could be cached.\n Default: `('GET', )`. Django setting: `CCRC_CACHE_REQ_METHDODS`\n * `codes`: a list/tuple with cacheable response codes.\n Default: `(200, )`. Django setting: `CCRC_CACHE_RSP_CODES`\n * `nocache_req`: a dictionary with request headers as keys and\n regular expressions as values (strings or compiled), so that when request\n has a header with value matching the expression,\n the response is never cached. The headers should be put in WSGI format,\n i.e. `'HTTP_X_FORWARDED_FOR'`. Default: `{}`.\n * `nocache_rsp`: a list of response headers that prevents response\n from being cached. Default: `('Set-Cookie', 'Vary')`.\n Django setting: `CCRC_NOCACHE_RSP_HEADERS`\n * `anonymous_only`: boolean selecting whether only anonymous requests\n should be served from the cache/responses cached.\n Default: `True`. Django setting: `CCRC_ANONYMOUS_REQ_ONLY`\n * `cache_cookies`: boolean, if False, requests with cookies will\n not be cached, otherwise cookies are ignored. Default: `False`.\n Django setting: `CCRC_CACHE_REQ_COOKIES`\n * `excluded_cookies`: if `cache_cookies` is False, cookies found in\n this list are ignored (considered as not set).\n If `cache_cookies` is True, response will not be cached if\n one of cookies listed is found in the request. Default: `()`.\n Django setting: `CCRC_EXCLUDED_REQ_COOKIES`\n * `include_scheme`: boolean selecting whether request scheme (http\n or https) should be used for the key. Default: `True`.\n Django setting: `CCRC_KEY_SCHEME`\n * `include_host`: boolean selecting whether requested Host: should\n be used for the key. Default: `True`. Django setting: `CCRC_KEY_HOST`\n * `hitmiss_header`: a tuple with three elements: header name,\n value for cache hit and another for cache miss.\n If set to `None`, the header is never added\n Default: `('X-Cache', 'Hit', 'Miss')'`. Django setting: `CCRC_HITMISS_HEADER`\n * `key_function`: optional callable that should be used instead of\n built-in key function.\n Has to accept request as its only argument and return either\n a string with the key or `None` if the request should not be cached.\n\n\n#### ResponseCache Features and Guidelines\n\n * Unlike `CacheMiddleware`, `cache_response` does not analyse `Cache-Control`\n header and does not change cache TTL. The header is cached along\n with the response just like any other header\n * Default settings for `cache_reponse` are chosen to be the safest, but in\n order to achieve better cache performance careful configuretion is required\n * By default, reponses with `Set-Cookie` and `Vary` headers are never cached,\n requests that have `Cookie` header are not cached either\n * Responses that have CSRF token(s) are never cached\n * Requests that have authenticated user associated with them are not cached\n by default\n * URL and Hostname are used to build the cache key, which could be a problem\n for certain caching engines due to their limitation to key characters and length.\n You are advised to use some hashing `KEY_FUNCTION` in your caching backend, like,\n for example, provided `calm_cache.contrib.sha1_key_func`\n\n\n## Legals\n\nLicense: BSD 3-clause\n\nCopyright (c) 2014, Fairfax Media Limited\nAll rights reserved.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/pitcrews/django-calm-cache", "keywords": "django cache memcache memcached minting pylibmc libmemcached", "license": "BSD 3-Clause", "maintainer": null, "maintainer_email": null, "name": "django-calm-cache", "package_url": "https://pypi.org/project/django-calm-cache/", "platform": "Platform Independent", "project_url": "https://pypi.org/project/django-calm-cache/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/pitcrews/django-calm-cache" }, "release_url": "https://pypi.org/project/django-calm-cache/0.9.2/", "requires_dist": null, "requires_python": null, "summary": "A set of useful tools that enhance the standard Django cache experience", "version": "0.9.2" }, "last_serial": 1426410, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "c4d0a559b809dd6ee5da262600966143", "sha256": "76a3a930b68acdd8e20302e2dd7553c7fcc1b2951b4e093c4d4404fab9d1aed9" }, "downloads": -1, "filename": "django-calm-cache-0.9.0.tar.gz", "has_sig": false, "md5_digest": "c4d0a559b809dd6ee5da262600966143", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10278, "upload_time": "2014-03-14T01:14:34", "url": "https://files.pythonhosted.org/packages/55/df/8fc6a5c7ab4416a630d102891e28858b3ede51c3e5ce31a92e33c2df1795/django-calm-cache-0.9.0.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "890ce5783c241a4616ef9d5cf84be2bf", "sha256": "04d6835a64d7df74e8c740efb13dd262bcf82e4bb112de02af81b57e4b897267" }, "downloads": -1, "filename": "django-calm-cache-0.9.1.tar.gz", "has_sig": false, "md5_digest": "890ce5783c241a4616ef9d5cf84be2bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10553, "upload_time": "2015-02-17T05:14:23", "url": "https://files.pythonhosted.org/packages/ae/57/471bd653653893afe36222398cc67085b336d8bf07a1ee68f52a9a25436d/django-calm-cache-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "b26c37a565ed5e928205ea3842fe9e5c", "sha256": "2cc5364ee87d7b50e330c86fa2669edc2401be1cbcb9e15640612c1fad441f08" }, "downloads": -1, "filename": "django-calm-cache-0.9.2.tar.gz", "has_sig": false, "md5_digest": "b26c37a565ed5e928205ea3842fe9e5c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10555, "upload_time": "2015-02-17T06:05:08", "url": "https://files.pythonhosted.org/packages/24/44/254f450eb8ece2fe8dbf98f7a146b79fe2cd84eb946315779fd2aa754fce/django-calm-cache-0.9.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b26c37a565ed5e928205ea3842fe9e5c", "sha256": "2cc5364ee87d7b50e330c86fa2669edc2401be1cbcb9e15640612c1fad441f08" }, "downloads": -1, "filename": "django-calm-cache-0.9.2.tar.gz", "has_sig": false, "md5_digest": "b26c37a565ed5e928205ea3842fe9e5c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10555, "upload_time": "2015-02-17T06:05:08", "url": "https://files.pythonhosted.org/packages/24/44/254f450eb8ece2fe8dbf98f7a146b79fe2cd84eb946315779fd2aa754fce/django-calm-cache-0.9.2.tar.gz" } ] }