1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

Added group avatar cache

This commit is contained in:
zhengxie
2012-11-21 20:48:36 +08:00
parent 1b686fc8cf
commit 8913e39904
4 changed files with 38 additions and 11 deletions

View File

@@ -5,7 +5,8 @@ from seahub.base.accounts import User
from avatar.settings import (AVATAR_DEFAULT_URL, AVATAR_CACHE_TIMEOUT,
AUTO_GENERATE_AVATAR_SIZES, AVATAR_DEFAULT_SIZE,
AVATAR_DEFAULT_NON_REGISTERED_URL)
AVATAR_DEFAULT_NON_REGISTERED_URL,
AUTO_GENERATE_GROUP_AVATAR_SIZES)
cached_funcs = set()
@@ -17,6 +18,12 @@ def get_cache_key(user_or_username, size, prefix):
user_or_username = user_or_username.username
return '%s_%s_%s' % (prefix, user_or_username, size)
def get_grp_cache_key(group_id, size):
"""
Returns a cache key consisten of a group id and iamge size.
"""
return 'Group_%s_%s' % (group_id, size)
def cache_result(func):
"""
Decorator to cache the result of functions that take a ``user`` and a
@@ -44,6 +51,16 @@ def invalidate_cache(user, size=None):
for size in sizes:
cache.delete(get_cache_key(user, size, prefix))
def invalidate_group_cache(group_id, size=None):
"""
Function to be called when saving or changing an user's avatars.
"""
sizes = set(AUTO_GENERATE_GROUP_AVATAR_SIZES)
if size is not None:
sizes.add(size)
for size in sizes:
cache.delete(get_grp_cache_key(group_id, size))
def get_default_avatar_url():
base_url = getattr(settings, 'STATIC_URL', None)
if not base_url: