diff --git a/compressor/cache.py b/compressor/cache.py index 62986b6..cec1015 100644 --- a/compressor/cache.py +++ b/compressor/cache.py @@ -62,18 +62,29 @@ def get_offline_manifest_filename(): return os.path.join(output_dir, settings.COMPRESS_OFFLINE_MANIFEST) +_offline_manifest = None + def get_offline_manifest(): - filename = get_offline_manifest_filename() - if default_storage.exists(filename): - return simplejson.load(default_storage.open(filename)) - else: - return {} + global _offline_manifest + if _offline_manifest is None: + filename = get_offline_manifest_filename() + if default_storage.exists(filename): + _offline_manifest = simplejson.load(default_storage.open(filename)) + else: + _offline_manifest = {} + return _offline_manifest + + +def flush_offline_manifest(): + global _offline_manifest + _offline_manifest = None def write_offline_manifest(manifest): filename = get_offline_manifest_filename() default_storage.save(filename, ContentFile(simplejson.dumps(manifest, indent=2))) + flush_offline_manifest() def get_templatetag_cachekey(compressor, mode, kind): diff --git a/compressor/tests/offline.py b/compressor/tests/offline.py index c59de2d..aa25777 100644 --- a/compressor/tests/offline.py +++ b/compressor/tests/offline.py @@ -9,6 +9,7 @@ except ImportError: from django.template import Template, Context from django.test import TestCase +from compressor.cache import flush_offline_manifest from compressor.conf import settings from compressor.exceptions import OfflineGenerationError from compressor.management.commands.compress import Command as CompressCommand @@ -134,6 +135,7 @@ class OfflineGenerationTestCase(OfflineTestCaseMixin, TestCase): expected_hash = "f5e179b8eca4" def test_rendering_without_compressing_raises_exception(self): + flush_offline_manifest() self.assertRaises(OfflineGenerationError, self.template.render, Context({}))