def render_cached(self, compressor, kind, mode): """ If enabled checks the cache for the given compressor's cache key and return a tuple of cache key and output """ cache_key = get_templatetag_cachekey(compressor, mode, kind) cache_content = cache_get(cache_key) return cache_key, cache_content
def render_cached(self, compressor, kind, mode): """ If enabled checks the cache for the given compressor's cache key and return a tuple of cache key and output """ cache_key = get_templatetag_cachekey(compressor, mode, kind) cache_content = cache_get(cache_key) return cache_key, cache_content
def render_cached(self, compressor, kind, mode, forced=False): """ If enabled checks the cache for the given compressor's cache key and return a tuple of cache key and output """ if settings.COMPRESS_ENABLED and not forced: cache_key = get_templatetag_cachekey(compressor, mode, kind) cache_content = cache_get(cache_key) return cache_key, cache_content return None, None
def render_cached(self, compressor, kind, mode, forced=False): """ If enabled checks the cache for the given compressor's cache key and return a tuple of cache key and output """ if settings.COMPRESS_ENABLED and not forced: cache_key = get_templatetag_cachekey(compressor, mode, kind) cache_content = cache_get(cache_key) return cache_key, cache_content return None, None
def compress(cache_key, content, kind, mode): logger = compress.get_logger() if cache_get(cache_key) is not None: logger.debug('No update required for %s', cache_key) return compressors = CompressorMixin().compressors compressor = get_class(compressors.get(kind), exception=ImproperlyConfigured) compressor = compressor(content=content) output = compressor.output(mode) cache_set(cache_key, output) logger.debug("Successfully updated cache key %s", cache_key)
def compiled_render(self, raw_content): if has_compressor: digest = hashlib.md5(smart_str(raw_content)).hexdigest() cached = cache_get(digest) if cached: return cached parser = HandlebarScriptParser() parser.feed(raw_content) non_template_content = parser.get_non_template_content() raw_templates = parser.get_templates() compile_root = tempfile.mkdtemp() content_parts = [] content_parts.append('<script type="text/javascript">') content_parts.append('window.addEventListener("load", function() {') for template in raw_templates: compressed = compress_template( compile_root, template.name, template.raw_content) content_parts.append(compressed) os.rmdir(compile_root) content_parts.append(self.get_templates_loaded_js()) content_parts.append('});') content_parts.append("</script>") content_parts.append(non_template_content) compiled = "".join(content_parts) if has_compressor: cache_set(digest, compiled) return compiled