Show More
@@ -1,86 +1,87 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2015-2020 RhodeCode GmbH |
|
3 | # Copyright (C) 2015-2020 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 | import logging | |
22 | from dogpile.cache import register_backend |
|
22 | from dogpile.cache import register_backend | |
23 |
|
23 | |||
24 | register_backend( |
|
24 | register_backend( | |
25 | "dogpile.cache.rc.memory_lru", "rhodecode.lib.rc_cache.backends", |
|
25 | "dogpile.cache.rc.memory_lru", "rhodecode.lib.rc_cache.backends", | |
26 | "LRUMemoryBackend") |
|
26 | "LRUMemoryBackend") | |
27 |
|
27 | |||
28 | register_backend( |
|
28 | register_backend( | |
29 | "dogpile.cache.rc.file_namespace", "rhodecode.lib.rc_cache.backends", |
|
29 | "dogpile.cache.rc.file_namespace", "rhodecode.lib.rc_cache.backends", | |
30 | "FileNamespaceBackend") |
|
30 | "FileNamespaceBackend") | |
31 |
|
31 | |||
32 | register_backend( |
|
32 | register_backend( | |
33 | "dogpile.cache.rc.redis", "rhodecode.lib.rc_cache.backends", |
|
33 | "dogpile.cache.rc.redis", "rhodecode.lib.rc_cache.backends", | |
34 | "RedisPickleBackend") |
|
34 | "RedisPickleBackend") | |
35 |
|
35 | |||
36 | register_backend( |
|
36 | register_backend( | |
37 | "dogpile.cache.rc.redis_msgpack", "rhodecode.lib.rc_cache.backends", |
|
37 | "dogpile.cache.rc.redis_msgpack", "rhodecode.lib.rc_cache.backends", | |
38 | "RedisMsgPackBackend") |
|
38 | "RedisMsgPackBackend") | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | log = logging.getLogger(__name__) |
|
41 | log = logging.getLogger(__name__) | |
42 |
|
42 | |||
43 | from . import region_meta |
|
43 | from . import region_meta | |
44 | from .utils import ( |
|
44 | from .utils import ( | |
45 | get_default_cache_settings, backend_key_generator, get_or_create_region, |
|
45 | get_default_cache_settings, backend_key_generator, get_or_create_region, | |
46 | clear_cache_namespace, make_region, InvalidationContext, |
|
46 | clear_cache_namespace, make_region, InvalidationContext, | |
47 | FreshRegionCache, ActiveRegionCache) |
|
47 | FreshRegionCache, ActiveRegionCache) | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | FILE_TREE_CACHE_VER = 'v4' |
|
50 | FILE_TREE_CACHE_VER = 'v4' | |
51 | LICENSE_CACHE_VER = 'v2' |
|
51 | LICENSE_CACHE_VER = 'v2' | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def configure_dogpile_cache(settings): |
|
54 | def configure_dogpile_cache(settings): | |
55 | cache_dir = settings.get('cache_dir') |
|
55 | cache_dir = settings.get('cache_dir') | |
56 | if cache_dir: |
|
56 | if cache_dir: | |
57 | region_meta.dogpile_config_defaults['cache_dir'] = cache_dir |
|
57 | region_meta.dogpile_config_defaults['cache_dir'] = cache_dir | |
58 |
|
58 | |||
59 | rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.']) |
|
59 | rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.']) | |
60 |
|
60 | |||
61 | # inspect available namespaces |
|
61 | # inspect available namespaces | |
62 | avail_regions = set() |
|
62 | avail_regions = set() | |
63 | for key in rc_cache_data.keys(): |
|
63 | for key in rc_cache_data.keys(): | |
64 | namespace_name = key.split('.', 1)[0] |
|
64 | namespace_name = key.split('.', 1)[0] | |
65 | avail_regions.add(namespace_name) |
|
65 | if namespace_name in avail_regions: | |
66 | log.debug('dogpile: found following cache regions: %s', avail_regions) |
|
66 | continue | |
67 |
|
67 | |||
68 | # register them into namespace |
|
68 | avail_regions.add(namespace_name) | |
69 | for region_name in avail_regions: |
|
69 | log.debug('dogpile: found following cache regions: %s', namespace_name) | |
|
70 | ||||
70 | new_region = make_region( |
|
71 | new_region = make_region( | |
71 |
name= |
|
72 | name=namespace_name, | |
72 | function_key_generator=None |
|
73 | function_key_generator=None | |
73 | ) |
|
74 | ) | |
74 |
|
75 | |||
75 |
new_region.configure_from_config(settings, 'rc_cache.{}.'.format( |
|
76 | new_region.configure_from_config(settings, 'rc_cache.{}.'.format(namespace_name)) | |
76 | new_region.function_key_generator = backend_key_generator(new_region.actual_backend) |
|
77 | new_region.function_key_generator = backend_key_generator(new_region.actual_backend) | |
77 | if log.isEnabledFor(logging.DEBUG): |
|
78 | if log.isEnabledFor(logging.DEBUG): | |
78 | region_args = dict(backend=new_region.actual_backend.__class__, |
|
79 | region_args = dict(backend=new_region.actual_backend.__class__, | |
79 | region_invalidator=new_region.region_invalidator.__class__) |
|
80 | region_invalidator=new_region.region_invalidator.__class__) | |
80 |
log.debug('dogpile: registering a new region `%s` %s', |
|
81 | log.debug('dogpile: registering a new region `%s` %s', namespace_name, region_args) | |
81 |
|
82 | |||
82 |
region_meta.dogpile_cache_regions[ |
|
83 | region_meta.dogpile_cache_regions[namespace_name] = new_region | |
83 |
|
84 | |||
84 |
|
85 | |||
85 | def includeme(config): |
|
86 | def includeme(config): | |
86 | configure_dogpile_cache(config.registry.settings) |
|
87 | configure_dogpile_cache(config.registry.settings) |
General Comments 0
You need to be logged in to leave comments.
Login now