django-cache-utils2
django-cache-utils2 provides cached decorator and invalidate function.
Installation
pip install django-cache-utils2
Usage
from cache_utils2 import cached, invalidate
@cached(60)
def foo(x, y=0):
print 'foo is called'
return x+y
foo(1, 2) # foo is called
foo(1, y=2)
foo(5, 6) # foo is called
foo(5, 6)
invalidate(foo, {'x': 1, 'y': 2})
foo(1, 2) # foo is called
foo(5, 6)
foo(x=2) # foo is called
foo(x=2)
class Foo(object):
@cached(60)
def foo(self, x, y):
print "foo is called"
return x+y
obj = Foo()
obj.foo(1,2) # foo is called
obj.foo(1,2)
invalidate(Foo.foo, {'x': 1, 'y': 2})
obj.foo(1,2) # foo is called
Django example
from django.db import models
from cache_utils2 import cached, invalidate
class CityManager(models.Manager):
# cache a method result. 'self' parameter is ignored
@cached(60*60*24)
def default(self):
return self.active()[0]
# cache a method result. 'self' parameter is ignored, args and
# kwargs are used to construct the cache key
@cached(60*60*24)
def get(self, *args, **kwargs):
return super(CityManager, self).get(*args, **kwargs)
class City(models.Model):
# ... field declarations
objects = CityManager()
# cache django model instance method result by instance pk
@cached(30, vary='self.pk')
def has_offers(self):
return self.offer_set.count() > 0
# invalidation of model methods
invalidate(City.has_offers, {'self.pk': 1}
Notes
If decorated function returns cache_utils2.NO_CACHE cache will be bypassed.
Running tests
Get the source code and run runtests.py.
Metadata
Release files for django-cache-utils2 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-cache-utils2-0.1.tar.gz | 5.2 kB | Without provenance | Details for django-cache-utils2-0.1.tar.gz |
Release files / django-cache-utils2-0.1.tar.gz
| Download URL | django-cache-utils2-0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b6efe29f7b7428aec54460e07fde214f6ac12f852e766e53dd6723a68600e8c
|
|
BLAKE2b-256 checksum How to use checksums |
1fb74c30b4da63883504f7cce16d293426b83a0c010ef3c9592fd63a310574ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-cache-utils2 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.