-
Notifications
You must be signed in to change notification settings - Fork 46
/
cachekeys.py
61 lines (44 loc) · 1.69 KB
/
cachekeys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# HTK Imports
from htk.cache import CustomCacheScheme
from htk.constants import *
class StaticAssetVersionCache(CustomCacheScheme):
"""Cache management object for static asset version for CSS and JavaScript
Usually refreshed at the end of a deploy
So that client browser cache doesn't have stale JS/CSS after a deploy
"""
def get_cache_duration(self):
duration = TIMEOUT_30_DAYS
return duration
class TaskCooldown(CustomCacheScheme):
"""Cache management object for not performing background tasks too frequently
Default cooldown: no more than once per day
"""
COOLDOWN_DURATION_SECONDS = TIMEOUT_24_HOURS
def get_cache_duration(self):
duration = self.COOLDOWN_DURATION_SECONDS
return duration
def has_cooldown(self):
"""Checks whether cooldown timer is still going
"""
_has_cooldown = bool(self.get())
return _has_cooldown
def reset_cooldown(self, force=False):
"""Resets cooldown timer
If `force` is `True`, resets the cooldown even there is time remaining.
Returns whether cooldown was reset, False if timer was still running
"""
if self.get() and not force:
was_reset = False
else:
self.cache_store()
was_reset = True
return was_reset
class BatchRelationshipEmailCooldown(TaskCooldown):
"""Cache management object for not sending out BatchRelationshipEmails too frequently
Default cooldown: no more than once per day
prekey = user.id
"""
COOLDOWN_DURATION_SECONDS = TIMEOUT_24_HOURS
def get_cache_duration(self):
duration = self.COOLDOWN_DURATION_SECONDS
return duration