Cache models via natural keys.
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')