@@ -21,22 +21,20 @@ class Marker:
21
21
pass
22
22
23
23
24
- CACHE_HERD_TIMEOUT = getattr (settings , "CACHE_HERD_TIMEOUT" , 60 )
25
-
26
-
27
- def _is_expired (x ):
28
- if x >= CACHE_HERD_TIMEOUT :
24
+ def _is_expired (x , herd_timeout ):
25
+ if x >= herd_timeout :
29
26
return True
30
- val = x + random .randint (1 , CACHE_HERD_TIMEOUT )
27
+ val = x + random .randint (1 , herd_timeout )
31
28
32
- if val >= CACHE_HERD_TIMEOUT :
29
+ if val >= herd_timeout :
33
30
return True
34
31
return False
35
32
36
33
37
34
class HerdClient (DefaultClient ):
38
35
def __init__ (self , * args , ** kwargs ):
39
36
self ._marker = Marker ()
37
+ self ._herd_timeout = getattr (settings , "CACHE_HERD_TIMEOUT" , 60 )
40
38
super ().__init__ (* args , ** kwargs )
41
39
42
40
def _pack (self , value , timeout ):
@@ -55,7 +53,7 @@ def _unpack(self, value):
55
53
now = int (time .time ())
56
54
if herd_timeout < now :
57
55
x = now - herd_timeout
58
- return unpacked , _is_expired (x )
56
+ return unpacked , _is_expired (x , self . _herd_timeout )
59
57
60
58
return unpacked , False
61
59
@@ -84,7 +82,7 @@ def set(
84
82
)
85
83
86
84
packed = self ._pack (value , timeout )
87
- real_timeout = timeout + CACHE_HERD_TIMEOUT
85
+ real_timeout = timeout + self . _herd_timeout
88
86
89
87
return super ().set (
90
88
key , packed , timeout = real_timeout , version = version , client = client , nx = nx
0 commit comments