##// END OF EJS Templates
core: updated copyrights to 2024
core: updated copyrights to 2024

File last commit:

r1327:278da2b3 default
r1327:278da2b3 default
Show More
__init__.py
114 lines | 3.6 KiB | text/x-python | PythonLexer
caches: replaced beaker with dogpile cache.
r483 # RhodeCode VCSServer provides access to different vcs backends via network.
core: updated copyrights to 2024
r1327 # Copyright (C) 2014-2024 RhodeCode GmbH
caches: replaced beaker with dogpile cache.
r483 #
# 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
caches: synced with CE code
r1113 import threading
ruff: code-cleanups
r1100
caches: replaced beaker with dogpile cache.
r483 from dogpile.cache import register_backend
ruff: code-cleanups
r1100
caches: synced with CE code
r1113 from . import region_meta
from .utils import (
backend_key_generator,
clear_cache_namespace,
get_default_cache_settings,
get_or_create_region,
make_region,
str2bool,
)
caches: synced code with ce changes
r1062 module_name = 'vcsserver'
caches: replaced beaker with dogpile cache.
r483
register_backend(
caches: synced code with ce changes
r1062 "dogpile.cache.rc.memory_lru", f"{module_name}.lib.rc_cache.backends",
caches: replaced beaker with dogpile cache.
r483 "LRUMemoryBackend")
caches: added redis backend as an option
r733 register_backend(
caches: synced code with ce changes
r1062 "dogpile.cache.rc.file_namespace", f"{module_name}.lib.rc_cache.backends",
caches: added redis backend as an option
r733 "FileNamespaceBackend")
register_backend(
caches: synced code with ce changes
r1062 "dogpile.cache.rc.redis", f"{module_name}.lib.rc_cache.backends",
caches: added redis backend as an option
r733 "RedisPickleBackend")
caches: add pickle/msgpack serializers for redis.
r735 register_backend(
caches: synced code with ce changes
r1062 "dogpile.cache.rc.redis_msgpack", f"{module_name}.lib.rc_cache.backends",
caches: add pickle/msgpack serializers for redis.
r735 "RedisMsgPackBackend")
caches: added redis backend as an option
r733
caches: replaced beaker with dogpile cache.
r483 log = logging.getLogger(__name__)
caches: synced with CE code
r1113
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 CACHE_OBJ_CACHE_VER = 'v2'
caches: new cache + archive cache implementation
r1121 CLEAR_DELETE = 'delete'
CLEAR_INVALIDATE = 'invalidate'
fix(caches): synced rc_cache module with rhodecode-ce
r1206 def async_creation_runner(cache, cache_key, creator, mutex):
caches: synced with CE code
r1113
def runner():
try:
value = creator()
fix(caches): synced rc_cache module with rhodecode-ce
r1206 cache.set(cache_key, value)
caches: synced with CE code
r1113 finally:
mutex.release()
thread = threading.Thread(target=runner)
thread.start()
caches: replaced beaker with dogpile cache.
r483
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]
caches: sync code from CE for faster load of cache engines.
r904 if namespace_name in avail_regions:
continue
caches: replaced beaker with dogpile cache.
r483
caches: sync code from CE for faster load of cache engines.
r904 avail_regions.add(namespace_name)
log.debug('dogpile: found following cache regions: %s', namespace_name)
caches: replaced beaker with dogpile cache.
r483 new_region = make_region(
caches: sync code from CE for faster load of cache engines.
r904 name=namespace_name,
caches: synced with CE code
r1113 function_key_generator=None,
async_creation_runner=None
caches: replaced beaker with dogpile cache.
r483 )
caches: synced with CE code
r1113 new_region.configure_from_config(settings, f'rc_cache.{namespace_name}.')
caches: don't use key_manglers instead prefix keys based on backend.
r734 new_region.function_key_generator = backend_key_generator(new_region.actual_backend)
caches: synced with CE code
r1113
async_creator = str2bool(settings.pop(f'rc_cache.{namespace_name}.async_creator', 'false'))
if async_creator:
log.debug('configuring region %s with async creator', new_region)
new_region.async_creation_runner = async_creation_runner
app: simplify logging, and startup time for cache backends.
r895 if log.isEnabledFor(logging.DEBUG):
caches: synced with CE code
r1113 region_args = dict(backend=new_region.actual_backend,
app: simplify logging, and startup time for cache backends.
r895 region_invalidator=new_region.region_invalidator.__class__)
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 log.debug('dogpile: registering a new region key=`%s` args=%s', namespace_name, region_args)
caches: sync code from CE for faster load of cache engines.
r904
region_meta.dogpile_cache_regions[namespace_name] = new_region
caches: replaced beaker with dogpile cache.
r483
def includeme(config):
configure_dogpile_cache(config.registry.settings)