##// END OF EJS Templates
deps: make dev-env build faster and cache rc_testdata
deps: make dev-env build faster and cache rc_testdata

File last commit:

r1062:837924f7 python3
r1090:9bb211d1 python3
Show More
__init__.py
80 lines | 2.9 KiB | text/x-python | PythonLexer
# RhodeCode VCSServer provides access to different vcs backends via network.
# Copyright (C) 2014-2020 RhodeCode GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import logging
from dogpile.cache import register_backend
module_name = 'vcsserver'
register_backend(
"dogpile.cache.rc.memory_lru", f"{module_name}.lib.rc_cache.backends",
"LRUMemoryBackend")
register_backend(
"dogpile.cache.rc.file_namespace", f"{module_name}.lib.rc_cache.backends",
"FileNamespaceBackend")
register_backend(
"dogpile.cache.rc.redis", f"{module_name}.lib.rc_cache.backends",
"RedisPickleBackend")
register_backend(
"dogpile.cache.rc.redis_msgpack", f"{module_name}.lib.rc_cache.backends",
"RedisMsgPackBackend")
log = logging.getLogger(__name__)
from . import region_meta
from .utils import (
get_default_cache_settings, backend_key_generator, get_or_create_region,
clear_cache_namespace, make_region)
def configure_dogpile_cache(settings):
cache_dir = settings.get('cache_dir')
if cache_dir:
region_meta.dogpile_config_defaults['cache_dir'] = cache_dir
rc_cache_data = get_default_cache_settings(settings, prefixes=['rc_cache.'])
# inspect available namespaces
avail_regions = set()
for key in rc_cache_data.keys():
namespace_name = key.split('.', 1)[0]
if namespace_name in avail_regions:
continue
avail_regions.add(namespace_name)
log.debug('dogpile: found following cache regions: %s', namespace_name)
new_region = make_region(
name=namespace_name,
function_key_generator=None
)
new_region.configure_from_config(settings, 'rc_cache.{}.'.format(namespace_name))
new_region.function_key_generator = backend_key_generator(new_region.actual_backend)
if log.isEnabledFor(logging.DEBUG):
region_args = dict(backend=new_region.actual_backend.__class__,
region_invalidator=new_region.region_invalidator.__class__)
log.debug('dogpile: registering a new region `%s` %s', namespace_name, region_args)
region_meta.dogpile_cache_regions[namespace_name] = new_region
def includeme(config):
configure_dogpile_cache(config.registry.settings)