django-natural-key-cache

Cache manager for caching django models by natural keys


Keywords
django-natural-key-cache
License
ISC
Install
pip install django-natural-key-cache==0.4

Documentation

Django Natural Key Cache

Build Status Coveralls Status Codecov Status Dependency Status Documentation Status PyPi version

Cache models via natural keys.

Quick Start

Add manager to model.

from django.db import models
from natural_key_cache.cache_manager import NaturalKeyCacheManager

class MyModel(models.Model):
    # Define natural keys, this can be ommited if id/pk is the natural key
    natural_keys = (
        'nat_key',
    )
    cache = NaturalKeyCacheManager(natural_keys)
    nat_key = models.CharField(max_length=32, unique=True)

Then access the cached model via the new manager.

MyModel.cache.get(nat_key='unique_instance')