Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding cache invalidation && moving cache key to model.

  • Loading branch information...
commit 7f24d720b0eadf40122d6469323c876d75d4887b 1 parent d77588d
@justinabrahms justinabrahms authored
View
2  django_website/context_processors.py
@@ -8,7 +8,7 @@ def recent_release(request):
if not recent_release:
recent_release = DocumentRelease.objects.default().version
cache.set(
- '%s_recent_release' % settings.CACHE_MIDDLEWARE_KEY_PREFIX,
+ DocumentRelease.DEFAULT_CACHE_KEY,
recent_release,
settings.CACHE_MIDDLEWARE_SECONDS,
)
View
7 django_website/docs/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.conf import settings
+from django.core.cache import cache
class DocumentReleaseManager(models.Manager):
def default(self):
@@ -9,6 +10,7 @@ class DocumentRelease(models.Model):
"""
A "release" of documentation -- i.e. English for v1.2.
"""
+ DEFAULT_CACHE_KEY = "%s_recent_release" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
SVN = 'svn'
SCM_CHOICES = (
(SVN, 'SVN'),
@@ -33,5 +35,10 @@ def save(self, *args, **kwargs):
# There can be only one. Default, that is.
if self.is_default:
DocumentRelease.objects.update(is_default=False)
+ cache.set(
+ self.DEFAULT_CACHE_KEY,
+ self.version,
+ settings.CACHE_MIDDLEWARE_SECONDS,
+ )
super(DocumentRelease, self).save(*args, **kwargs)

0 comments on commit 7f24d72

Please sign in to comment.
Something went wrong with that request. Please try again.