Show More
@@ -207,6 +207,7 b' def includeme(config):' | |||
|
207 | 207 | # Includes which are required. The application would fail without them. |
|
208 | 208 | config.include('pyramid_mako') |
|
209 | 209 | config.include('pyramid_beaker') |
|
210 | config.include('rhodecode.lib.caches') | |
|
210 | 211 | |
|
211 | 212 | config.include('rhodecode.authentication') |
|
212 | 213 | config.include('rhodecode.integrations') |
@@ -499,6 +499,7 b' def bootstrap_config(request):' | |||
|
499 | 499 | # allow pyramid lookup in testing |
|
500 | 500 | config.include('pyramid_mako') |
|
501 | 501 | config.include('pyramid_beaker') |
|
502 | config.include('rhodecode.lib.caches') | |
|
502 | 503 | |
|
503 | 504 | add_events_routes(config) |
|
504 | 505 |
@@ -47,18 +47,48 b' DEFAULT_CACHE_MANAGER_CONFIG = {' | |||
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | |
|
50 | def get_default_cache_settings(settings): | |
|
51 | cache_settings = {} | |
|
52 | for key in settings.keys(): | |
|
53 | for prefix in ['beaker.cache.', 'cache.']: | |
|
54 | if key.startswith(prefix): | |
|
55 | name = key.split(prefix)[1].strip() | |
|
56 | cache_settings[name] = settings[key].strip() | |
|
57 | return cache_settings | |
|
58 | ||
|
59 | ||
|
60 | # set cache regions for beaker so celery can utilise it | |
|
61 | def configure_caches(settings, default_region_settings=None): | |
|
62 | cache_settings = {'regions': None} | |
|
63 | # main cache settings used as default ... | |
|
64 | cache_settings.update(get_default_cache_settings(settings)) | |
|
65 | default_region_settings = default_region_settings or \ | |
|
66 | {'type': DEFAULT_CACHE_MANAGER_CONFIG['type']} | |
|
67 | if cache_settings['regions']: | |
|
68 | for region in cache_settings['regions'].split(','): | |
|
69 | region = region.strip() | |
|
70 | region_settings = default_region_settings.copy() | |
|
71 | for key, value in cache_settings.items(): | |
|
72 | if key.startswith(region): | |
|
73 | region_settings[key.split('.')[1]] = value | |
|
74 | log.debug('Configuring cache region `%s` with settings %s', | |
|
75 | region, region_settings) | |
|
76 | configure_cache_region( | |
|
77 | region, region_settings, cache_settings) | |
|
78 | ||
|
79 | ||
|
50 | 80 | def configure_cache_region( |
|
51 |
region_name, region_ |
|
|
81 | region_name, region_settings, default_cache_kw, default_expire=60): | |
|
52 | 82 | default_type = default_cache_kw.get('type', 'memory') |
|
53 | 83 | default_lock_dir = default_cache_kw.get('lock_dir') |
|
54 | 84 | default_data_dir = default_cache_kw.get('data_dir') |
|
55 | 85 | |
|
56 |
region_ |
|
|
57 |
region_ |
|
|
58 |
region_ |
|
|
59 |
region_ |
|
|
86 | region_settings['lock_dir'] = region_settings.get('lock_dir', default_lock_dir) | |
|
87 | region_settings['data_dir'] = region_settings.get('data_dir', default_data_dir) | |
|
88 | region_settings['type'] = region_settings.get('type', default_type) | |
|
89 | region_settings['expire'] = int(region_settings.get('expire', default_expire)) | |
|
60 | 90 | |
|
61 |
beaker.cache.cache_regions[region_name] = region_ |
|
|
91 | beaker.cache.cache_regions[region_name] = region_settings | |
|
62 | 92 | |
|
63 | 93 | |
|
64 | 94 | def get_cache_manager(region_name, cache_name, custom_ttl=None): |
@@ -233,3 +263,7 b' class InvalidationContext(object):' | |||
|
233 | 263 | Session().rollback() |
|
234 | 264 | if self.raise_exception: |
|
235 | 265 | raise |
|
266 | ||
|
267 | ||
|
268 | def includeme(config): | |
|
269 | configure_caches(config.registry.settings) |
@@ -619,35 +619,6 b' def repo2db_mapper(initial_repo_list, re' | |||
|
619 | 619 | return added, removed |
|
620 | 620 | |
|
621 | 621 | |
|
622 | def get_default_cache_settings(settings): | |
|
623 | cache_settings = {} | |
|
624 | for key in settings.keys(): | |
|
625 | for prefix in ['beaker.cache.', 'cache.']: | |
|
626 | if key.startswith(prefix): | |
|
627 | name = key.split(prefix)[1].strip() | |
|
628 | cache_settings[name] = settings[key].strip() | |
|
629 | return cache_settings | |
|
630 | ||
|
631 | ||
|
632 | # set cache regions for beaker so celery can utilise it | |
|
633 | def add_cache(settings): | |
|
634 | from rhodecode.lib import caches | |
|
635 | cache_settings = {'regions': None} | |
|
636 | # main cache settings used as default ... | |
|
637 | cache_settings.update(get_default_cache_settings(settings)) | |
|
638 | ||
|
639 | if cache_settings['regions']: | |
|
640 | for region in cache_settings['regions'].split(','): | |
|
641 | region = region.strip() | |
|
642 | region_settings = {} | |
|
643 | for key, value in cache_settings.items(): | |
|
644 | if key.startswith(region): | |
|
645 | region_settings[key.split('.')[1]] = value | |
|
646 | ||
|
647 | caches.configure_cache_region( | |
|
648 | region, region_settings, cache_settings) | |
|
649 | ||
|
650 | ||
|
651 | 622 | def load_rcextensions(root_path): |
|
652 | 623 | import rhodecode |
|
653 | 624 | from rhodecode.config import conf |
@@ -390,7 +390,7 b' beaker.cache.sql_cache_short.key_length ' | |||
|
390 | 390 | |
|
391 | 391 | ## default is memory cache, configure only if required |
|
392 | 392 | ## using multi-node or multi-worker setup |
|
393 | beaker.cache.auth_plugins.type = memory | |
|
393 | #beaker.cache.auth_plugins.type = memory | |
|
394 | 394 | #beaker.cache.auth_plugins.lock_dir = %(here)s/data/cache/auth_plugin_lock |
|
395 | 395 | #beaker.cache.auth_plugins.url = postgresql://postgres:secret@localhost/rhodecode |
|
396 | 396 | #beaker.cache.auth_plugins.url = mysql://root:secret@127.0.0.1/rhodecode |
General Comments 0
You need to be logged in to leave comments.
Login now