@@ -145,19 +145,46 @@ def test_cache_region_has_default_key_length():
145
145
assert 'short_term_without_key_length' in cache_regions
146
146
147
147
@cache .region ('short_term_without_key_length' )
148
- def load (person ):
148
+ def load_without_key_length (person ):
149
149
now = datetime .now ()
150
150
return "Hi there %s, its currently %s" % (person , now )
151
151
152
152
# Ensure that same person gets same time
153
- msg = load ('fred' )
154
- msg2 = load ('fred' )
153
+ msg = load_without_key_length ('fred' )
154
+ msg2 = load_without_key_length ('fred' )
155
155
assert msg == msg2 , (msg , msg2 )
156
156
157
157
# Ensure that different person gets different time
158
- msg3 = load ('george' )
158
+ msg3 = load_without_key_length ('george' )
159
159
assert msg3 .split (',' )[- 1 ] != msg2 .split (',' )[- 1 ]
160
160
161
161
finally :
162
162
# throw away region for this test
163
163
cache_regions .pop ('short_term_without_key_length' , None )
164
+
165
+
166
+ def test_cache_region_expire_is_always_int ():
167
+ try :
168
+ cache = CacheManager (cache_regions = {
169
+ 'short_term_with_string_expire' : {
170
+ 'expire' : '60' ,
171
+ 'type' : 'memory'
172
+ }
173
+ })
174
+
175
+ # Check CacheManager registered the region in global regions
176
+ assert 'short_term_with_string_expire' in cache_regions
177
+
178
+ @cache .region ('short_term_with_string_expire' )
179
+ def load_with_str_expire (person ):
180
+ now = datetime .now ()
181
+ return "Hi there %s, its currently %s" % (person , now )
182
+
183
+ # Ensure that same person gets same time
184
+ msg = load_with_str_expire ('fred' )
185
+ msg2 = load_with_str_expire ('fred' )
186
+ assert msg == msg2 , (msg , msg2 )
187
+
188
+ finally :
189
+ # throw away region for this test
190
+ cache_regions .pop ('short_term_with_string_expire' , None )
0 commit comments