##// END OF EJS Templates
caches: use a better logic to clear cache keys
super-admin -
r4845:58a1f157 default
parent child Browse files
Show More
@@ -21,14 +21,14 b''
21 21 import os
22 22 import atexit
23 23 import logging
24 import signal
24 25
25 26 log = logging.getLogger(__name__)
26 27
27 cache_keys_by_pid = []
28 cache_keys_by_pid = set()
28 29
29 30
30 @atexit.register
31 def free_cache_keys():
31 def free_cache_keys(*args):
32 32 ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER')
33 33 if ssh_cmd:
34 34 return
@@ -38,8 +38,14 b' def free_cache_keys():'
38 38
39 39 if cache_keys_by_pid:
40 40 try:
41 for cache_key in cache_keys_by_pid:
42 CacheKey.query().filter(CacheKey.cache_key == cache_key).delete()
41 for cache_proc in cache_keys_by_pid:
42 CacheKey.query().filter(CacheKey.cache_key.startswith(cache_proc)).delete()
43 43 Session().commit()
44 cache_keys_by_pid.clear()
44 45 except Exception:
45 46 log.warn('Failed to clear keys, exiting gracefully')
47
48
49 atexit.register(free_cache_keys)
50 signal.signal(signal.SIGTERM, free_cache_keys)
51 signal.signal(signal.SIGINT, free_cache_keys)
@@ -354,6 +354,7 b' class InvalidationContext(object):'
354 354 self.cache_key = compute_key_from_params(uid)
355 355 self.cache_key = 'proc:{}|thread:{}|params:{}'.format(
356 356 self.proc_id, self.thread_id, self.cache_key)
357 self.proc_key = 'proc:{}'.format(self.proc_id)
357 358 self.compute_time = 0
358 359
359 360 def get_or_create_cache_obj(self, cache_type, invalidation_namespace=''):
@@ -372,7 +373,7 b' class InvalidationContext(object):'
372 373 cache_state_uid = first_cache_obj.cache_state_uid
373 374 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args,
374 375 cache_state_uid=cache_state_uid)
375 cache_key_meta.cache_keys_by_pid.append(self.cache_key)
376 cache_key_meta.cache_keys_by_pid.add(self.proc_key)
376 377
377 378 return cache_obj
378 379
General Comments 0
You need to be logged in to leave comments. Login now