CachedCompilerFilter: also cache empty files
This commit is contained in:
@@ -224,7 +224,7 @@ class CachedCompilerFilter(CompilerFilter):
|
|||||||
if self.mimetype in settings.COMPRESS_CACHEABLE_PRECOMPILERS:
|
if self.mimetype in settings.COMPRESS_CACHEABLE_PRECOMPILERS:
|
||||||
key = self.get_cache_key()
|
key = self.get_cache_key()
|
||||||
data = cache.get(key)
|
data = cache.get(key)
|
||||||
if data:
|
if data is not None:
|
||||||
return data
|
return data
|
||||||
filtered = super(CachedCompilerFilter, self).input(**kwargs)
|
filtered = super(CachedCompilerFilter, self).input(**kwargs)
|
||||||
cache.set(key, filtered, settings.COMPRESS_REBUILD_TIMEOUT)
|
cache.set(key, filtered, settings.COMPRESS_REBUILD_TIMEOUT)
|
||||||
|
@@ -10,7 +10,7 @@ from django.test import TestCase
|
|||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
from compressor.cache import get_hashed_mtime, get_hashed_content
|
from compressor.cache import cache, get_hashed_mtime, get_hashed_content
|
||||||
from compressor.conf import settings
|
from compressor.conf import settings
|
||||||
from compressor.css import CssCompressor
|
from compressor.css import CssCompressor
|
||||||
from compressor.utils import find_command
|
from compressor.utils import find_command
|
||||||
@@ -134,6 +134,15 @@ class PrecompilerTestCase(TestCase):
|
|||||||
self.assertEqual("body { color:#990; }", compiler.input())
|
self.assertEqual("body { color:#990; }", compiler.input())
|
||||||
self.assertIsNotNone(compiler.infile) # Not cached
|
self.assertIsNotNone(compiler.infile) # Not cached
|
||||||
|
|
||||||
|
def test_precompiler_caches_empty_files(self):
|
||||||
|
command = '%s %s -f {infile} -o {outfile}' % (sys.executable, self.test_precompiler)
|
||||||
|
compiler = CachedCompilerFilter(command=command, **self.cached_precompiler_args)
|
||||||
|
self.assertEqual("body { color:#990; }", compiler.input())
|
||||||
|
|
||||||
|
cache.set(compiler.get_cache_key(), "")
|
||||||
|
compiler = CachedCompilerFilter(command=command, **self.cached_precompiler_args)
|
||||||
|
self.assertEqual("", compiler.input())
|
||||||
|
|
||||||
|
|
||||||
class CssMinTestCase(TestCase):
|
class CssMinTestCase(TestCase):
|
||||||
def test_cssmin_filter(self):
|
def test_cssmin_filter(self):
|
||||||
|
Reference in New Issue
Block a user