Show More
@@ -1,75 +1,77 b'' | |||||
1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
1 | # RhodeCode VCSServer provides access to different vcs backends via network. | |
2 | # Copyright (C) 2014-2020 RhodeCode GmbH |
|
2 | # Copyright (C) 2014-2020 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or modify |
|
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by |
|
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or |
|
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. |
|
7 | # (at your option) any later version. | |
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 General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import logging |
|
18 | import logging | |
19 | from dogpile.cache import register_backend |
|
19 | from dogpile.cache import register_backend | |
20 |
|
20 | |||
21 | register_backend( |
|
21 | register_backend( | |
22 | "dogpile.cache.rc.memory_lru", "vcsserver.lib.rc_cache.backends", |
|
22 | "dogpile.cache.rc.memory_lru", "vcsserver.lib.rc_cache.backends", | |
23 | "LRUMemoryBackend") |
|
23 | "LRUMemoryBackend") | |
24 |
|
24 | |||
25 | register_backend( |
|
25 | register_backend( | |
26 | "dogpile.cache.rc.file_namespace", "vcsserver.lib.rc_cache.backends", |
|
26 | "dogpile.cache.rc.file_namespace", "vcsserver.lib.rc_cache.backends", | |
27 | "FileNamespaceBackend") |
|
27 | "FileNamespaceBackend") | |
28 |
|
28 | |||
29 | register_backend( |
|
29 | register_backend( | |
30 | "dogpile.cache.rc.redis", "vcsserver.lib.rc_cache.backends", |
|
30 | "dogpile.cache.rc.redis", "vcsserver.lib.rc_cache.backends", | |
31 | "RedisPickleBackend") |
|
31 | "RedisPickleBackend") | |
32 |
|
32 | |||
33 | register_backend( |
|
33 | register_backend( | |
34 | "dogpile.cache.rc.redis_msgpack", "vcsserver.lib.rc_cache.backends", |
|
34 | "dogpile.cache.rc.redis_msgpack", "vcsserver.lib.rc_cache.backends", | |
35 | "RedisMsgPackBackend") |
|
35 | "RedisMsgPackBackend") | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | log = logging.getLogger(__name__) |
|
38 | log = logging.getLogger(__name__) | |
39 |
|
39 | |||
40 | from . import region_meta |
|
40 | from . import region_meta | |
41 | from .utils import (get_default_cache_settings, backend_key_generator, make_region) |
|
41 | from .utils import (get_default_cache_settings, backend_key_generator, make_region) | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def configure_dogpile_cache(settings): |
|
44 | def configure_dogpile_cache(settings): | |
45 | cache_dir = settings.get('cache_dir') |
|
45 | cache_dir = settings.get('cache_dir') | |
46 | if cache_dir: |
|
46 | if cache_dir: | |
47 | region_meta.dogpile_config_defaults['cache_dir'] = cache_dir |
|
47 | region_meta.dogpile_config_defaults['cache_dir'] = cache_dir | |
48 |
|
48 | |||
49 | rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.']) |
|
49 | rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.']) | |
50 |
|
50 | |||
51 | # inspect available namespaces |
|
51 | # inspect available namespaces | |
52 | avail_regions = set() |
|
52 | avail_regions = set() | |
53 | for key in rc_cache_data.keys(): |
|
53 | for key in rc_cache_data.keys(): | |
54 | namespace_name = key.split('.', 1)[0] |
|
54 | namespace_name = key.split('.', 1)[0] | |
55 | avail_regions.add(namespace_name) |
|
55 | if namespace_name in avail_regions: | |
56 | log.debug('dogpile: found following cache regions: %s', avail_regions) |
|
56 | continue | |
57 |
|
57 | |||
58 | # register them into namespace |
|
58 | avail_regions.add(namespace_name) | |
59 | for region_name in avail_regions: |
|
59 | log.debug('dogpile: found following cache regions: %s', namespace_name) | |
|
60 | ||||
60 | new_region = make_region( |
|
61 | new_region = make_region( | |
61 |
name= |
|
62 | name=namespace_name, | |
62 | function_key_generator=None |
|
63 | function_key_generator=None | |
63 | ) |
|
64 | ) | |
64 |
|
65 | |||
65 |
new_region.configure_from_config(settings, 'rc_cache.{}.'.format( |
|
66 | new_region.configure_from_config(settings, 'rc_cache.{}.'.format(namespace_name)) | |
66 | new_region.function_key_generator = backend_key_generator(new_region.actual_backend) |
|
67 | new_region.function_key_generator = backend_key_generator(new_region.actual_backend) | |
67 | if log.isEnabledFor(logging.DEBUG): |
|
68 | if log.isEnabledFor(logging.DEBUG): | |
68 | region_args = dict(backend=new_region.actual_backend.__class__, |
|
69 | region_args = dict(backend=new_region.actual_backend.__class__, | |
69 | region_invalidator=new_region.region_invalidator.__class__) |
|
70 | region_invalidator=new_region.region_invalidator.__class__) | |
70 |
log.debug('dogpile: registering a new region `%s` %s', |
|
71 | log.debug('dogpile: registering a new region `%s` %s', namespace_name, region_args) | |
71 | region_meta.dogpile_cache_regions[region_name] = new_region |
|
72 | ||
|
73 | region_meta.dogpile_cache_regions[namespace_name] = new_region | |||
72 |
|
74 | |||
73 |
|
75 | |||
74 | def includeme(config): |
|
76 | def includeme(config): | |
75 | configure_dogpile_cache(config.registry.settings) |
|
77 | configure_dogpile_cache(config.registry.settings) |
General Comments 0
You need to be logged in to leave comments.
Login now