mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Use slugify on the cache key and append it with a hash of the full key to prevent too long keys (looking at you, Memcache).
This commit is contained in:
parent
7247ae77a9
commit
7aa9b49064
1 changed files with 5 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.utils.hashcompat import md5_constructor
|
||||
from django.templates.defaultfilters import slugify
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
|
@ -14,7 +16,9 @@ def get_cache_key(user_or_username, size, prefix):
|
|||
"""
|
||||
if isinstance(user_or_username, User):
|
||||
user_or_username = user_or_username.username
|
||||
return '%s_%s_%s' % (prefix, user_or_username, size)
|
||||
key = '%s_%s_%s' % (prefix, user_or_username, size)
|
||||
return '%s_%s' % (slugify(key)[:100], md5_constructor(key).hexdigest())
|
||||
|
||||
|
||||
def cache_result(func):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue