**BACKWARDS-INCOMPATIBLE** Added new COMPRESS_CACHE_KEY_FUNCTION setting to define the function which is used to create the cache key. Fixes #61.
This commit is contained in:
@@ -5,8 +5,10 @@ import time
|
|||||||
from django.core.cache import get_cache
|
from django.core.cache import get_cache
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.utils.hashcompat import md5_constructor
|
from django.utils.hashcompat import md5_constructor
|
||||||
|
from django.utils.importlib import import_module
|
||||||
|
|
||||||
from compressor.conf import settings
|
from compressor.conf import settings
|
||||||
|
from compressor.utils import get_mod_func
|
||||||
|
|
||||||
|
|
||||||
def get_hexdigest(plaintext, length=None):
|
def get_hexdigest(plaintext, length=None):
|
||||||
@@ -15,10 +17,18 @@ def get_hexdigest(plaintext, length=None):
|
|||||||
return digest[:length]
|
return digest[:length]
|
||||||
return digest
|
return digest
|
||||||
|
|
||||||
|
def simple_cachekey(key):
|
||||||
|
return 'django_compressor.%s' % smart_str(key)
|
||||||
|
|
||||||
def get_cachekey(key):
|
def socket_cachekey(key):
|
||||||
return ("django_compressor.%s.%s" % (socket.gethostname(), key))
|
return "django_compressor.%s.%s" % (socket.gethostname(), smart_str(key))
|
||||||
|
|
||||||
|
try:
|
||||||
|
mod_name, func_name = get_mod_func(settings.COMPRESS_CACHE_KEY_FUNCTION)
|
||||||
|
get_cachekey = getattr(import_module(mod_name), func_name)
|
||||||
|
except (AttributeError, ImportError), e:
|
||||||
|
raise ImportError("Couldn't import cache key function %s: %s" %
|
||||||
|
(settings.COMPRESS_CACHE_KEY_FUNCTION, e))
|
||||||
|
|
||||||
def get_mtime_cachekey(filename):
|
def get_mtime_cachekey(filename):
|
||||||
return get_cachekey("mtime.%s" % get_hexdigest(filename))
|
return get_cachekey("mtime.%s" % get_hexdigest(filename))
|
||||||
|
@@ -46,6 +46,8 @@ class CompressorSettings(AppSettings):
|
|||||||
|
|
||||||
# the cache backend to use
|
# the cache backend to use
|
||||||
CACHE_BACKEND = None
|
CACHE_BACKEND = None
|
||||||
|
# the dotted path to the function that creates the cache key
|
||||||
|
CACHE_KEY_FUNCTION = 'compressor.cache.simple_cachekey'
|
||||||
# rebuilds the cache every 30 days if nothing has changed.
|
# rebuilds the cache every 30 days if nothing has changed.
|
||||||
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
|
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
|
||||||
# the upper bound on how long any compression should take to be generated
|
# the upper bound on how long any compression should take to be generated
|
||||||
|
@@ -9,6 +9,13 @@ HEAD
|
|||||||
has the potential to breaking lots of apps but on the other hand
|
has the potential to breaking lots of apps but on the other hand
|
||||||
will help find bugs.
|
will help find bugs.
|
||||||
|
|
||||||
|
- **BACKWARDS-INCOMPATIBLE** The default function to create the cache
|
||||||
|
key stopped containing the server hostname. Instead the cache key
|
||||||
|
now only has the form ``'django_compressor.<KEY>'``.
|
||||||
|
|
||||||
|
To revert to the previous way simply set the ``COMPRESS_CACHE_KEY_FUNCTION``
|
||||||
|
to ``'django_compressor.cache.socket_cachekey'``.
|
||||||
|
|
||||||
- Added Compass filter (beta).
|
- Added Compass filter (beta).
|
||||||
|
|
||||||
- Fixed compiler filters on Windows.
|
- Fixed compiler filters on Windows.
|
||||||
|
Reference in New Issue
Block a user