-class KeyValueManager(models.Manager):
-
- def create_cache_key(self, key):
- return "%s:keyvalue:%s" % (settings.APP_URL, key)
-
- def save_to_cache(self, instance):
- cache.set(self.create_cache_key(instance.key), instance, 2592000)
-
- def remove_from_cache(self, instance):
- cache.delete(self.create_cache_key(instance.key))
-
- def get(self, **kwargs):
- if 'key' in kwargs:
- instance = cache.get(self.create_cache_key(kwargs['key']))
-
- if instance is None:
- instance = super(KeyValueManager, self).get(**kwargs)
- self.save_to_cache(instance)
-
- return instance
-
- else:
- return super(KeyValueManager, self).get(**kwargs)
-
-class KeyValue(models.Model):