jezdez/django_compressor — Issue #210: Enable cache even if COMPRESS_ENABLED is False
Author: akheron
Created: 2012-02-10 11:55:30+00:00
State: open

Currently, the cache is not used when `COMPRESS_ENABLED` is `False`. This makes page reloads very slow during development when I only want precompilation to run, especially if there are many files to be precompiled.

Here's a simple patch for always enabling the cache:

```patch
diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py
index 7d9643b..6be278d 100644
--- a/compressor/templatetags/compress.py
+++ b/compressor/templatetags/compress.py
@@ -71,16 +71,14 @@ class CompressorMixin(object):
'enabled but key "%s" is missing from offline manifest. '
'You may need to run "python manage.py compress".' % key)

- def render_cached(self, compressor, kind, mode, forced=False):
+ 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
"""
- 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
+ cache_key = get_templatetag_cachekey(compressor, mode, kind)
+ cache_content = cache_get(cache_key)
+ return cache_key, cache_content

def render_compressed(self, context, kind, mode, forced=False):

@@ -99,7 +97,7 @@ class CompressorMixin(object):
compressor = self.get_compressor(context, kind)

# Prepare the actual compressor and check cache
- cache_key, cache_content = self.render_cached(compressor, kind, mode, forced=forced)
+ cache_key, cache_content = self.render_cached(compressor, kind, mode)
if cache_content is not None:
return cache_content

```

All files in a single `{% compress %}` block are still precompiled when only one of them changes, but sorting files into different blocks based on how often they change helps.