Show More
@@ -1,68 +1,75 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2015-2018 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 | import logging | |
|
21 | 22 | from dogpile.cache import register_backend |
|
22 | 23 | from dogpile.cache import make_region |
|
23 | 24 | |
|
24 | 25 | register_backend( |
|
25 | 26 | "dogpile.cache.rc.memory_lru", "rhodecode.lib.rc_cache.backends", |
|
26 | 27 | "LRUMemoryBackend") |
|
27 | 28 | |
|
28 | 29 | register_backend( |
|
29 | 30 | "dogpile.cache.rc.file_namespace", "rhodecode.lib.rc_cache.backends", |
|
30 | 31 | "FileNamespaceBackend") |
|
31 | 32 | |
|
32 | 33 | register_backend( |
|
33 | 34 | "dogpile.cache.rc.redis", "rhodecode.lib.rc_cache.backends", |
|
34 | 35 | "RedisPickleBackend") |
|
35 | 36 | |
|
36 | 37 | |
|
38 | log = logging.getLogger(__name__) | |
|
39 | ||
|
37 | 40 | from . import region_meta |
|
38 | 41 | from .utils import ( |
|
39 | 42 | get_default_cache_settings, key_generator, get_or_create_region, |
|
40 | 43 | clear_cache_namespace) |
|
41 | 44 | |
|
42 | 45 | |
|
43 | 46 | def configure_dogpile_cache(settings): |
|
44 | 47 | cache_dir = settings.get('cache_dir') |
|
45 | 48 | if cache_dir: |
|
46 | 49 | region_meta.dogpile_config_defaults['cache_dir'] = cache_dir |
|
47 | 50 | |
|
48 | 51 | rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.']) |
|
49 | 52 | |
|
50 | 53 | # inspect available namespaces |
|
51 | 54 | avail_regions = set() |
|
52 | 55 | for key in rc_cache_data.keys(): |
|
53 | 56 | namespace_name = key.split('.', 1)[0] |
|
54 | 57 | avail_regions.add(namespace_name) |
|
58 | log.debug('dogpile: found following cache regions: %s', avail_regions) | |
|
55 | 59 | |
|
56 | 60 | # register them into namespace |
|
57 | 61 | for region_name in avail_regions: |
|
58 | 62 | new_region = make_region( |
|
59 | 63 | name=region_name, |
|
60 | 64 | function_key_generator=key_generator |
|
61 | 65 | ) |
|
62 | 66 | |
|
63 | 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 | 71 | region_meta.dogpile_cache_regions[region_name] = new_region |
|
65 | 72 | |
|
66 | 73 | |
|
67 | 74 | def includeme(config): |
|
68 | 75 | configure_dogpile_cache(config.registry.settings) |
General Comments 0
You need to be logged in to leave comments.
Login now