Cache access to cache object

This commit is contained in:
Raphael Michel
2017-10-17 18:00:07 +02:00
parent 7e1e259897
commit 03133dc1fd
12 changed files with 115 additions and 23 deletions

View File

@@ -264,7 +264,7 @@ class Event(EventMixin, LoggedModel):
def save(self, *args, **kwargs):
obj = super().save(*args, **kwargs)
self.get_cache().clear()
self.cache.clear()
return obj
def get_plugins(self) -> "list[str]":
@@ -281,6 +281,19 @@ class Event(EventMixin, LoggedModel):
Django's built-in cache backends, but puts you into an isolated environment for
this event, so you don't have to prefix your cache keys. In addition, the cache
is being cleared every time the event or one of its related objects change.
.. deprecated:: 1.9
Use the property ``cache`` instead.
"""
return self.cache
@cached_property
def cache(self):
"""
Returns an :py:class:`ObjectRelatedCache` object. This behaves equivalent to
Django's built-in cache backends, but puts you into an isolated environment for
this event, so you don't have to prefix your cache keys. In addition, the cache
is being cleared every time the event or one of its related objects change.
"""
from pretix.base.cache import ObjectRelatedCache
@@ -578,6 +591,16 @@ class SubEvent(EventMixin, LoggedModel):
data.update({v.property.name: v.value for v in self.meta_values.select_related('property').all()})
return data
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
if self.event:
self.event.cache.clear()
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if self.event:
self.event.cache.clear()
def generate_invite_token():
return get_random_string(length=32, allowed_chars=string.ascii_lowercase + string.digits)
@@ -677,6 +700,16 @@ class EventMetaValue(LoggedModel):
class Meta:
unique_together = ('event', 'property')
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
if self.event:
self.event.cache.clear()
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if self.event:
self.event.cache.clear()
class SubEventMetaValue(LoggedModel):
"""
@@ -697,3 +730,13 @@ class SubEventMetaValue(LoggedModel):
class Meta:
unique_together = ('subevent', 'property')
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
if self.subevent:
self.subevent.event.cache.clear()
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if self.subevent:
self.subevent.event.cache.clear()