def _clear_caches(self, template_context): """ Clear our caches from both the request object and memcache. """ request = template_context['request'] try: del request._content_cache_dict except AttributeError: pass cache.delete(content_dict_cache_key())
def _clear_caches(self, template_context): """ Clear our caches from both the request object and memcache. """ request = template_context['request'] try: del request._content_cache_dict except AttributeError: pass cache.delete(content_dict_cache_key())
def _get_content_dict(self, template_context): """ An efficient way for us to fetch content data without hitting the DB multiple times on the same request. Tries to get the content by: 1. getting it from a temporary cache on the request object, 2. getting it from memcache, 3. getting it from the database. Returns a dict of dicts. """ request = template_context['request'] #The first time we fetch the content on a given request we store it on the request object try: return request._content_cache_dict except AttributeError: pass cache_key = content_dict_cache_key() content_dict = cache.get(cache_key) if content_dict is None: content_objects = ContentItem.objects.all() content_dict = {obj.key: obj.content_dict for obj in content_objects} cache.set(cache_key, content_dict, get_cache_timeout()) request._content_cache_dict = content_dict return content_dict
def _get_content_dict(self, template_context): """ An efficient way for us to fetch content data without hitting the DB multiple times on the same request. Tries to get the content by: 1. getting it from a temporary cache on the request object, 2. getting it from memcache, 3. getting it from the database. Returns a dict of dicts. """ request = template_context['request'] #The first time we fetch the content on a given request we store it on the request object try: return request._content_cache_dict except AttributeError: pass cache_key = content_dict_cache_key() content_dict = cache.get(cache_key) if content_dict is None: content_objects = ContentItem.objects.all() content_dict = { obj.key: obj.content_dict for obj in content_objects } cache.set(cache_key, content_dict, get_cache_timeout()) request._content_cache_dict = content_dict return content_dict