##// END OF EJS Templates
cache-keys: register and self cleanup cache keys used for invalidation to prevent leaking lot of them into DB on worker recycle
marcink -
r3890:2f6d1dda default
parent child Browse files
Show More
@@ -0,0 +1,35 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2015-2019 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 import atexit
22 import logging
23
24 log = logging.getLogger(__name__)
25
26 cache_keys_by_pid = []
27
28
29 @atexit.register
30 def free_cache_keys():
31 from rhodecode.model.db import Session, CacheKey
32 log.info('Clearing %s cache keys', len(cache_keys_by_pid))
33 for cache_key in cache_keys_by_pid:
34 CacheKey.query().filter(CacheKey.cache_key == cache_key).delete()
35 Session().commit()
@@ -32,7 +32,8 b' from rhodecode.lib.utils import safe_str'
32 from rhodecode.lib.utils2 import safe_unicode, str2bool
32 from rhodecode.lib.utils2 import safe_unicode, str2bool
33 from rhodecode.model.db import Session, CacheKey, IntegrityError
33 from rhodecode.model.db import Session, CacheKey, IntegrityError
34
34
35 from . import region_meta
35 from rhodecode.lib.rc_cache import cache_key_meta
36 from rhodecode.lib.rc_cache import region_meta
36
37
37 log = logging.getLogger(__name__)
38 log = logging.getLogger(__name__)
38
39
@@ -304,6 +305,8 b' class InvalidationContext(object):'
304 cache_state_uid = first_cache_obj.cache_state_uid
305 cache_state_uid = first_cache_obj.cache_state_uid
305 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args,
306 cache_obj = CacheKey(self.cache_key, cache_args=new_cache_args,
306 cache_state_uid=cache_state_uid)
307 cache_state_uid=cache_state_uid)
308 cache_key_meta.cache_keys_by_pid.append(self.cache_key)
309
307 return cache_obj
310 return cache_obj
308
311
309 def __enter__(self):
312 def __enter__(self):
General Comments 0
You need to be logged in to leave comments. Login now