def get_cache_key(page, language): """ Create the cache key for the current page and language """ from cms.cache import _get_cache_key site_id = page.site_id return _get_cache_key('page_meta', page, language, site_id)
def get_cache_key(request, page, lang, site_id, title): """ Create the cache key for the current page and tag type """ from cms.cache import _get_cache_key from cms.templatetags.cms_tags import _get_page_by_untyped_arg from cms.models import Page if not isinstance(page, Page): page = _get_page_by_untyped_arg(page, request, site_id) if not site_id: site_id = page.site_id if not title: return _get_cache_key('page_tags', page, '', site_id) + '_type:tags_list' else: return _get_cache_key('title_tags', page, lang, site_id) + '_type:tags_list'
def get_cache_key(page): """ Create the cache key for the current page and language """ try: site_id = page.node.site_id except AttributeError: site_id = page.site_id return _get_cache_key('page_sitemap', page, 'default', site_id)
def _show_placeholder_attr_for_page(context, placeholder_name, plugin_class_name, plugin_attr, page_lookup, lang=None, site=None, cache_result=True): validate_placeholder_name(placeholder_name) request = context.get('request', False) site_id = get_site_id(site) if not request: return {'content': ''} if lang is None: lang = get_language_from_request(request) if cache_result: base_key = _get_cache_key('_show_placeholder_for_page', page_lookup, lang, site_id) cache_key = _clean_key('%s_placeholder:%s' % (base_key, placeholder_name) ) + plugin_class_name + '.' + plugin_attr cached_value = cache.get(cache_key) if isinstance(cached_value, dict): # new style _restore_sekizai(context, cached_value['sekizai']) return {'content': mark_safe(cached_value['content'])} elif isinstance(cached_value, string_types): # old style return {'content': mark_safe(cached_value)} page = _get_page_by_untyped_arg(page_lookup, request, site_id) if not page: return {'content': ''} watcher = Watcher(context) placeholder = _get_placeholder(page, page, context, placeholder_name) content = get_placholder_attr(placeholder, placeholder_name, plugin_class_name, plugin_attr) changes = watcher.get_changes() if cache_result: cache.set(cache_key, { 'content': content, 'sekizai': changes }, get_cms_setting('CACHE_DURATIONS')['content']) if content: return {'content': mark_safe(content)} return {'content': ''}
def get_cache_key(page, language): """ Create the cache key for the current page and language """ try: from cms.cache import _get_cache_key except ImportError: from cms.templatetags.cms_tags import _get_cache_key site_id = page.site_id return _get_cache_key('page_meta', page, language, site_id)
def get_cache_key(page, language): """ Create the cache key for the current page and language """ from cms.cache import _get_cache_key try: site_id = page.node.site_id except AttributeError: # CMS_3_4 site_id = page.site_id return _get_cache_key('page_meta', page, language, site_id)
def get_cache_key(request, page, lang, site_id, title): """ Create the cache key for the current page and tag type """ try: from cms.cache import _get_cache_key from cms.templatetags.cms_tags import _get_page_by_untyped_arg except ImportError: from cms.templatetags.cms_tags import _get_page_by_untyped_arg, _get_cache_key from cms.models import Page if not isinstance(page, Page): page = _get_page_by_untyped_arg(page, request, site_id) if not site_id: site_id = page.site_id if not title: return _get_cache_key('page_tags', page, '', site_id) + '_type:tags_list' else: return _get_cache_key('title_tags', page, lang, site_id) + '_type:tags_list'
def _show_placeholder_attr_for_page( context, placeholder_name, plugin_class_name, plugin_attr, page_lookup, lang=None, site=None, cache_result=True): validate_placeholder_name(placeholder_name) request = context.get('request', False) site_id = get_site_id(site) if not request: return {'content': ''} if lang is None: lang = get_language_from_request(request) if cache_result: base_key = _get_cache_key( '_show_placeholder_for_page', page_lookup, lang, site_id) cache_key = _clean_key( '%s_placeholder:%s' % ( base_key, placeholder_name )) + plugin_class_name + '.' + plugin_attr cached_value = cache.get(cache_key) if isinstance(cached_value, dict): # new style _restore_sekizai(context, cached_value['sekizai']) return {'content': mark_safe(cached_value['content'])} elif isinstance(cached_value, string_types): # old style return {'content': mark_safe(cached_value)} page = _get_page_by_untyped_arg(page_lookup, request, site_id) if not page: return {'content': ''} watcher = Watcher(context) placeholder = _get_placeholder(page, page, context, placeholder_name) content = get_placholder_attr( placeholder, placeholder_name, plugin_class_name, plugin_attr) changes = watcher.get_changes() if cache_result: cache.set( cache_key, { 'content': content, 'sekizai': changes }, get_cms_setting('CACHE_DURATIONS')['content']) if content: return {'content': mark_safe(content)} return {'content': ''}
def page_titleextension(context, page_id, extension, do_cache=None): do_cache = is_caching_desired(do_cache=do_cache) request = context.get('request') is_draft = request and hasattr(request, 'user') and use_draft(request) if do_cache: lang = get_language() site_id = settings.SITE_ID cache_duration = get_cms_setting('CACHE_DURATIONS')['content'] page_cache_key = _get_cache_key('page_titleextension', page_id, lang, site_id) cache_key = '{}_{}_{}'.format(page_cache_key, is_draft, extension) cached = cache.get(cache_key) if cached: if cached == NO_EXTENSION: return None return cached try: page = Page.objects.get(pk=page_id) if is_draft: page = page.get_draft_object() else: page = page.get_public_object() except NameError: raise ImportError( 'django-cms is required when using page_titleextension tag') except Page.DoesNotExist: return None if not page: return None try: title_extension = getattr(page.get_title_obj(), extension) except ObjectDoesNotExist: if do_cache: cache.set(cache_key, NO_EXTENSION, timeout=cache_duration) return None else: if do_cache: cache.set(cache_key, title_extension, timeout=cache_duration) return title_extension
def _placeholder_page_cache_key(page_lookup, lang, site_id, placeholder_name): base_key = _get_cache_key('_show_placeholder_for_page', page_lookup, lang, site_id) return _clean_key('%s_placeholder:%s' % (base_key, placeholder_name))
def get_cache_key(page): """ Create the cache key for the current page and language """ site_id = page.node.site_id return _get_cache_key("page_sitemap", page, "default", site_id)
def get_cache_key(page): """ Create the cache key for the current page and language """ site_id = page.site_id return _get_cache_key('page_sitemap', page, 'default', site_id)
def _page_url_key(page_lookup, lang, site_id): return _get_cache_key('page_url', page_lookup, lang, site_id) + '_type:absolute_url'
def _placeholder_page_cache_key(page_lookup, lang, site_id, placeholder_name): base_key = _get_cache_key("_show_placeholder_for_page", page_lookup, lang, site_id) return _clean_key("%s_placeholder:%s" % (base_key, placeholder_name))