Skip to main content

An easy-to-use cache for Django models.

Project description

# django-model-cache

An easy-to-use cache for Django models.

This code has been developed and used in a production environment for one year.

## How to use
There follows some examples of use. For further examples, see `tests/simple/`.

class Brand(models.Model):
name = models.CharField(max_length=128)

cache = CacheController(timeout=None)

class Product(models.Model):
code = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
brand = models.ForeignKey('Brand')
name = models.CharField(max_length=255)

cache = CacheController(fields=['code', ('brand_id', 'name')], related_fields=['brand'], timeout=None)

class Meta:
unique_together = ('name', 'brand')

# Get a product by pk.
product = Product.cache.get(pk=1)

# Get a product by a unique key.
product = Product.cache.get(code='A001')

# Load the related models.

## How to test

Just run `tox` or install the dependencies and run `cd tests/ && ./ test`.

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-model-cache-1.0.1.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

django_model_cache-1.0.1-py3-none-any.whl (5.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page