do not try to keep Tag and Template in a cache, it does not play well with transaction rollbacks

We should only fill a cache of models when outside of a transaction.
This commit is contained in:
Benjamin Dauvergne 2014-01-30 21:36:01 +01:00
parent 398931f83c
commit fd5c7bae01
1 changed files with 0 additions and 13 deletions

View File

@ -1,25 +1,12 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models.query import QuerySet
from django.db.models import Q
from django.core.cache import cache
from model_utils.managers import PassThroughManager
JOURNAL_METADATA_CACHE_TIMEOUT = 3600
class CachedQuerySet(QuerySet):
def get_cached(self, **kwargs):
key = tuple(sorted(kwargs.iteritems()))
hash1 = key.__hash__()
hash2 = ('x', key).__hash__()
key = 'dj-cache-%s-%s-%s' % (self.model.__name__, hash1, hash2)
instance = cache.get(key)
if instance is not None:
return instance
instance, created = self.get_or_create(**kwargs)
if JOURNAL_METADATA_CACHE_TIMEOUT:
cache.set(key, instance, JOURNAL_METADATA_CACHE_TIMEOUT)
return instance