Skip to main content

Cache function result with args for Django.

Project description

=====
Cache Fn
=====
Use django cache to cache the `function(*arg, **kw)` with timeout.

Quick start
-----------

1. Install::

pip install django-cache-fn

1. Add "cache_fn" to your INSTALLED_APPS setting like this::

INSTALLED_APPS = [
...
'cache_fn',
]

2. Start to use it in code::

from cache_fn.decorators import cache_fn

@cache_fn(prefix='myprefix', timeout=3600)
def foo(k1, k2):
return "%s %s"%(k1, k2)

Usage
--------

def cache_fn(timeout=1, prefix=None, cache_ttl=MEMCACHE_MAX_EXPIRATION):
"""
Retrieve data from cache if cacheable and no-stale,
otherise refresh synchronously and cache it.
* timeout: The stale timeout which would be handled in the decorator.
* prefix: The prefix of cache key.
* cache_ttl: The TTL(time to live) of key in memcache.
NOTE: For HttpResponse, we just cache the response whose status code is 200.
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cache-fn-1.0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file django-cache-fn-1.0.tar.gz.

File metadata

  • Download URL: django-cache-fn-1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5

File hashes

Hashes for django-cache-fn-1.0.tar.gz
Algorithm Hash digest
SHA256 e700a159334bd0d2cddf372e83e51a94c08926330fa7e83fb1cbb38f7c0f73f0
MD5 a9c334d4f6000ac826005aebece65076
BLAKE2b-256 4f12a95d66e9799d6b8444ba1d826a0a54bed2145bf5f0bf2dc7ff5f6a181f44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page