Added ability to use a different cache backend.

This commit is contained in:
Jannis Leidel
2010-09-16 11:25:29 +02:00
parent 8de7eb0a8b
commit ec5a0dd96a
8 changed files with 38 additions and 6 deletions

View File

@@ -39,6 +39,13 @@ they will be silently stripped.
If COMPRESS is False (defaults to the opposite of DEBUG) the compress tag
simply returns exactly what it was given, to ease development.
.. note::
For production sites it is advisable to use a real cache backend such as
memcached to speed up the checks of compressed files. Make sure you
set the ``CACHE_BACKEND`` setting (or ``COMPRESS_CACHE_BACKEND``)
appropriately.
CSS Notes:
**********
@@ -161,6 +168,14 @@ The backends included in ``compressor``:
See `Dependencies`_ for more info about the packages you need for each parser.
``COMPRESS_CACHE_BACKEND``
--------------------------
:Default: ``CACHE_BACKEND``
The backend to use for caching, in case you want to use a different cache
backend for compressor. Defaults to the ``CACHE_BACKEND`` setting.
``COMPRESS_REBUILD_TIMEOUT``
----------------------------

4
compressor/cache.py Normal file
View File

@@ -0,0 +1,4 @@
from django.core.cache import get_cache
from compressor.conf import settings
cache = get_cache(settings.CACHE_BACKEND)

View File

@@ -1,7 +1,5 @@
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
MEDIA_URL = getattr(settings, 'COMPRESS_URL', settings.MEDIA_URL)
MEDIA_ROOT = getattr(settings, 'COMPRESS_ROOT', settings.MEDIA_ROOT)
OUTPUT_DIR = getattr(settings, 'COMPRESS_OUTPUT_DIR', 'CACHE')
@@ -49,3 +47,6 @@ PARSER = getattr(settings, 'COMPRESS_PARSER', 'compressor.parser.BeautifulSoupPa
# Allows changing verbosity from the settings.
VERBOSE = getattr(settings, "COMPRESS_VERBOSE", False)
# the cache backend to use
CACHE_BACKEND = getattr(settings, 'COMPRESS_CACHE_BACKEND', settings.CACHE_BACKEND)

View File

@@ -2,9 +2,9 @@ import fnmatch
import os
from optparse import make_option
from django.core.cache import cache
from django.core.management.base import NoArgsCommand, CommandError
from compressor.cache import cache
from compressor.conf import settings
from compressor.utils import get_mtime, get_mtime_cachekey

View File

@@ -1,8 +1,9 @@
import time
from django import template
from django.core.cache import cache
from compressor import CssCompressor, JsCompressor
from compressor.cache import cache
from compressor.conf import settings

View File

@@ -1,5 +1,5 @@
import os
from django.core.cache import cache
from compressor.cache import cache
from compressor.conf import settings
from compressor.exceptions import FilterError

View File

@@ -7,6 +7,7 @@ from django.template import Template, Context, TemplateSyntaxError
from django.test import TestCase
from django.core.files.storage import get_storage_class
from django.conf import settings as django_settings
from django.core.cache.backends import dummy
from compressor import CssCompressor, JsCompressor, storage
from compressor.conf import settings
@@ -364,3 +365,10 @@ class VerboseTestCase(CompressorTestCase):
def setUp(self):
super(VerboseTestCase, self).setUp()
setattr(settings, "COMPRESS_VERBOSE", True)
class CacheBackendTestCase(CompressorTestCase):
def test_correct_backend(self):
from compressor.cache import cache
self.assertEqual(cache.__class__, dummy.CacheClass)

View File

@@ -22,4 +22,7 @@ TEMPLATE_LOADERS = (
TEMPLATE_DIRS = (
join(TEST_DIR, 'templates'),
)
)
COMPRESS_CACHE_BACKEND = "dummy://"