Skip to content

Commit 72a219f

Browse files
committed
Added cache related settings.
1 parent 1a40064 commit 72a219f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

compressor/conf/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@
2020
COMPRESS_JS_FILTERS = []
2121

2222
COMPRESS_DATA_URI_MIN_SIZE = getattr(settings, 'COMPRESS_DATA_URI_MIN_SIZE', 1024)
23+
24+
# rebuilds the cache every 30 days if nothing has changed.
25+
REBUILD_TIMEOUT = getattr(settings, 'COMPRESS_REBUILD_TIMEOUT', 2592000) # 30 days
26+
27+
# the upper bound on how long any compression should take to be generated
28+
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
29+
MINT_DELAY = getattr(settings, 'COMPRESS_MINT_DELAY', 30) # 30 seconds

compressor/templatetags/compress.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
from compressor import CssCompressor, JsCompressor
66
from compressor.conf import settings
77

8-
# MINT_DELAY is an upper bound on how long any
9-
# value should take to be generated (in seconds)
10-
MINT_DELAY = 30
11-
DEFAULT_TIMEOUT = 300
12-
138
register = template.Library()
149

1510
class CompressorNode(template.Node):
@@ -25,13 +20,13 @@ def cache_get(self, key):
2520
if (time.time() > refresh_time) and not refreshed:
2621
# Store the stale value while the cache
2722
# revalidates for another MINT_DELAY seconds.
28-
self.cache_set(key, val, timeout=MINT_DELAY, refreshed=True)
23+
self.cache_set(key, val, timeout=settings.MINT_DELAY, refreshed=True)
2924
return None
3025
return val
3126

32-
def cache_set(self, key, val, timeout=DEFAULT_TIMEOUT, refreshed=False):
27+
def cache_set(self, key, val, timeout=settings.REBUILD_TIMEOUT, refreshed=False):
3328
refresh_time = timeout + time.time()
34-
real_timeout = timeout + MINT_DELAY
29+
real_timeout = timeout + settings.MINT_DELAY
3530
packed_val = (val, refresh_time, refreshed)
3631
return cache.set(key, packed_val, real_timeout)
3732

@@ -47,8 +42,7 @@ def render(self, context):
4742
if output is None:
4843
try:
4944
output = compressor.output()
50-
# rebuilds the cache every 30 days if nothing has changed.
51-
self.cache_set(compressor.cachekey, output, 2591000)
45+
self.cache_set(compressor.cachekey, output)
5246
except:
5347
from traceback import format_exc
5448
raise Exception(format_exc())

0 commit comments

Comments
 (0)