Populate cache of Stream objects on server restart.

(imported from commit 131eeddc5ebe5cc0db2554514a730d2750078012)
This commit is contained in:
Tim Abbott 2013-03-26 12:07:20 -04:00
parent 4fd1281f3c
commit cc065a3c90
1 changed files with 13 additions and 1 deletions

View File

@ -1,10 +1,11 @@
# This file needs to be different from cache.py because cache.py
# cannot import anything from zephyr.models or we'd have an import
# loop
from zephyr.models import Message, UserProfile
from zephyr.models import Message, UserProfile, Stream, get_stream_cache_key
from zephyr.lib.cache import cache_with_key, djcache, message_cache_key, \
user_profile_by_email_cache_key, user_profile_by_user_cache_key, \
user_by_id_cache_key, user_profile_by_id_cache_key
import logging
MESSAGE_CACHE_SIZE = 25000
@ -40,6 +41,17 @@ def populate_user_cache():
djcache.set_many(items_for_memcached, timeout=3600*24*7)
def populate_stream_cache():
items_for_memcached = {}
for stream in Stream.objects.select_related().all():
items_for_memcached[get_stream_cache_key(stream.name, stream.realm_id)] = (stream,)
djcache.set_many(items_for_memcached, timeout=3600*24*7)
def fill_memcached_caches():
populate_user_cache()
logging.info("Succesfully populated user cache!")
populate_stream_cache()
logging.info("Succesfully populated stream cache!")
populate_message_cache()
logging.info("Succesfully populated mesasge cache!")