Added cache related settings.
This commit is contained in:
@@ -20,3 +20,10 @@ if COMPRESS_JS_FILTERS is None:
|
|||||||
COMPRESS_JS_FILTERS = []
|
COMPRESS_JS_FILTERS = []
|
||||||
|
|
||||||
COMPRESS_DATA_URI_MIN_SIZE = getattr(settings, 'COMPRESS_DATA_URI_MIN_SIZE', 1024)
|
COMPRESS_DATA_URI_MIN_SIZE = getattr(settings, 'COMPRESS_DATA_URI_MIN_SIZE', 1024)
|
||||||
|
|
||||||
|
# rebuilds the cache every 30 days if nothing has changed.
|
||||||
|
REBUILD_TIMEOUT = getattr(settings, 'COMPRESS_REBUILD_TIMEOUT', 2592000) # 30 days
|
||||||
|
|
||||||
|
# the upper bound on how long any compression should take to be generated
|
||||||
|
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
|
||||||
|
MINT_DELAY = getattr(settings, 'COMPRESS_MINT_DELAY', 30) # 30 seconds
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ from django.core.cache import cache
|
|||||||
from compressor import CssCompressor, JsCompressor
|
from compressor import CssCompressor, JsCompressor
|
||||||
from compressor.conf import settings
|
from compressor.conf import settings
|
||||||
|
|
||||||
# MINT_DELAY is an upper bound on how long any
|
|
||||||
# value should take to be generated (in seconds)
|
|
||||||
MINT_DELAY = 30
|
|
||||||
DEFAULT_TIMEOUT = 300
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
class CompressorNode(template.Node):
|
class CompressorNode(template.Node):
|
||||||
@@ -25,13 +20,13 @@ class CompressorNode(template.Node):
|
|||||||
if (time.time() > refresh_time) and not refreshed:
|
if (time.time() > refresh_time) and not refreshed:
|
||||||
# Store the stale value while the cache
|
# Store the stale value while the cache
|
||||||
# revalidates for another MINT_DELAY seconds.
|
# revalidates for another MINT_DELAY seconds.
|
||||||
self.cache_set(key, val, timeout=MINT_DELAY, refreshed=True)
|
self.cache_set(key, val, timeout=settings.MINT_DELAY, refreshed=True)
|
||||||
return None
|
return None
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def cache_set(self, key, val, timeout=DEFAULT_TIMEOUT, refreshed=False):
|
def cache_set(self, key, val, timeout=settings.REBUILD_TIMEOUT, refreshed=False):
|
||||||
refresh_time = timeout + time.time()
|
refresh_time = timeout + time.time()
|
||||||
real_timeout = timeout + MINT_DELAY
|
real_timeout = timeout + settings.MINT_DELAY
|
||||||
packed_val = (val, refresh_time, refreshed)
|
packed_val = (val, refresh_time, refreshed)
|
||||||
return cache.set(key, packed_val, real_timeout)
|
return cache.set(key, packed_val, real_timeout)
|
||||||
|
|
||||||
@@ -47,8 +42,7 @@ class CompressorNode(template.Node):
|
|||||||
if output is None:
|
if output is None:
|
||||||
try:
|
try:
|
||||||
output = compressor.output()
|
output = compressor.output()
|
||||||
# rebuilds the cache every 30 days if nothing has changed.
|
self.cache_set(compressor.cachekey, output)
|
||||||
self.cache_set(compressor.cachekey, output, 2591000)
|
|
||||||
except:
|
except:
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
raise Exception(format_exc())
|
raise Exception(format_exc())
|
||||||
|
|||||||
Reference in New Issue
Block a user