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