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