Skip to content

Commit

Permalink
Merge pull request #1066 from benjaoming/cache-key-memcached-issue
Browse files Browse the repository at this point in the history
slugify cache keys because of memcached issue with spaces
  • Loading branch information
benjaoming committed Aug 14, 2020
2 parents 523bc08 + eafb13d commit e5d6b97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release_notes.rst
Expand Up @@ -20,6 +20,7 @@ Fixed
~~~~~

* Do not fail prematurely during Django checks framework (rare issue) :url-issue:`1059` (Benjamin Bach)
* Cache keys failing in memcached if username contains space characters (rare) :url-issue:`1065` (Benjamin Bach)


0.6
Expand Down
9 changes: 7 additions & 2 deletions src/wiki/models/article.py
Expand Up @@ -10,6 +10,7 @@
from django.urls import reverse
from django.utils import translation
from django.utils.safestring import mark_safe
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from mptt.models import MPTTModel
from wiki import managers
Expand Down Expand Up @@ -219,15 +220,19 @@ def get_cache_key(self):
"""Returns per-article cache key."""
lang = translation.get_language()

return "wiki:article:{id}:{lang}".format(
key_raw = "wiki:article:{id}:{lang}".format(
id=self.current_revision.id if self.current_revision else self.id, lang=lang
)
# https://github.com/django-wiki/django-wiki/issues/1065
return slugify(key_raw, allow_unicode=True)

def get_cache_content_key(self, user=None):
"""Returns per-article-user cache key."""
return "{key}:{user}".format(
key_raw = "{key}:{user}".format(
key=self.get_cache_key(), user=user.get_username() if user else ""
)
# https://github.com/django-wiki/django-wiki/issues/1065
return slugify(key_raw, allow_unicode=True)

def get_cached_content(self, user=None):
"""Returns cached version of rendered article.
Expand Down

0 comments on commit e5d6b97

Please sign in to comment.