Skip to content

Commit

Permalink
Merge pull request jazzband#32 from selwin/develop
Browse files Browse the repository at this point in the history
Fixed an issue where ``get_cache_key`` may produce invalid memcached keys
  • Loading branch information
jezdez committed May 7, 2012
2 parents f3fc408 + bb4e7ce commit d926d6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dbtemplates/tests.py
Expand Up @@ -13,7 +13,7 @@

from dbtemplates.conf import settings
from dbtemplates.models import Template
from dbtemplates.utils.cache import get_cache_backend
from dbtemplates.utils.cache import get_cache_backend, get_cache_key
from dbtemplates.utils.template import (get_template_source,
check_template_syntax)
from dbtemplates.management.commands.sync_templates import (FILES_TO_DATABASE,
Expand Down Expand Up @@ -141,3 +141,7 @@ def test_check_template_syntax(self):
name='good.html', content='{% if foo %}Bar{% endif %}')
self.assertFalse(check_template_syntax(bad_template)[0])
self.assertTrue(check_template_syntax(good_template)[0])

def test_get_cache_name(self):
name = 'name with spaces'
self.assertEqual(get_cache_key(name), 'dbtemplates::name-with-spaces::1')
3 changes: 2 additions & 1 deletion dbtemplates/utils/cache.py
@@ -1,6 +1,7 @@
from django.core.cache import get_cache

from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify

from dbtemplates.conf import settings

Expand All @@ -13,7 +14,7 @@ def get_cache_backend():

def get_cache_key(name):
current_site = Site.objects.get_current()
return 'dbtemplates::%s::%s' % (name, current_site.pk)
return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk)


def get_cache_notfound_key(name):
Expand Down

0 comments on commit d926d6c

Please sign in to comment.