##// END OF EJS Templates
core: speed up cache loading
milka -
r4594:46592d9a stable
parent child Browse files
Show More
@@ -1,86 +1,87 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2015-2020 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22 from dogpile.cache import register_backend
23 23
24 24 register_backend(
25 25 "dogpile.cache.rc.memory_lru", "rhodecode.lib.rc_cache.backends",
26 26 "LRUMemoryBackend")
27 27
28 28 register_backend(
29 29 "dogpile.cache.rc.file_namespace", "rhodecode.lib.rc_cache.backends",
30 30 "FileNamespaceBackend")
31 31
32 32 register_backend(
33 33 "dogpile.cache.rc.redis", "rhodecode.lib.rc_cache.backends",
34 34 "RedisPickleBackend")
35 35
36 36 register_backend(
37 37 "dogpile.cache.rc.redis_msgpack", "rhodecode.lib.rc_cache.backends",
38 38 "RedisMsgPackBackend")
39 39
40 40
41 41 log = logging.getLogger(__name__)
42 42
43 43 from . import region_meta
44 44 from .utils import (
45 45 get_default_cache_settings, backend_key_generator, get_or_create_region,
46 46 clear_cache_namespace, make_region, InvalidationContext,
47 47 FreshRegionCache, ActiveRegionCache)
48 48
49 49
50 50 FILE_TREE_CACHE_VER = 'v4'
51 51 LICENSE_CACHE_VER = 'v2'
52 52
53 53
54 54 def configure_dogpile_cache(settings):
55 55 cache_dir = settings.get('cache_dir')
56 56 if cache_dir:
57 57 region_meta.dogpile_config_defaults['cache_dir'] = cache_dir
58 58
59 59 rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.'])
60 60
61 61 # inspect available namespaces
62 62 avail_regions = set()
63 63 for key in rc_cache_data.keys():
64 64 namespace_name = key.split('.', 1)[0]
65 avail_regions.add(namespace_name)
66 log.debug('dogpile: found following cache regions: %s', avail_regions)
65 if namespace_name in avail_regions:
66 continue
67 67
68 # register them into namespace
69 for region_name in avail_regions:
68 avail_regions.add(namespace_name)
69 log.debug('dogpile: found following cache regions: %s', namespace_name)
70
70 71 new_region = make_region(
71 name=region_name,
72 name=namespace_name,
72 73 function_key_generator=None
73 74 )
74 75
75 new_region.configure_from_config(settings, 'rc_cache.{}.'.format(region_name))
76 new_region.configure_from_config(settings, 'rc_cache.{}.'.format(namespace_name))
76 77 new_region.function_key_generator = backend_key_generator(new_region.actual_backend)
77 78 if log.isEnabledFor(logging.DEBUG):
78 79 region_args = dict(backend=new_region.actual_backend.__class__,
79 80 region_invalidator=new_region.region_invalidator.__class__)
80 log.debug('dogpile: registering a new region `%s` %s', region_name, region_args)
81 log.debug('dogpile: registering a new region `%s` %s', namespace_name, region_args)
81 82
82 region_meta.dogpile_cache_regions[region_name] = new_region
83 region_meta.dogpile_cache_regions[namespace_name] = new_region
83 84
84 85
85 86 def includeme(config):
86 87 configure_dogpile_cache(config.registry.settings)
General Comments 0
You need to be logged in to leave comments. Login now