##// END OF EJS Templates
deps: bumped attrs==24.2.0
deps: bumped attrs==24.2.0

File last commit:

r5487:c594e70d default
r5638:e7de4707 default
Show More
__init__.py
80 lines | 2.3 KiB | text/x-python | PythonLexer
feat(archive-cache): implemented s3 based backend for filecaches
r5433 # Copyright (C) 2015-2024 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# 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 Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
from .backends.fanout_cache import FileSystemFanoutCache
from .backends.objectstore_cache import ObjectStoreCache
from .utils import archive_iterator # noqa
from .lock import ArchiveCacheGenerationLock # noqa
log = logging.getLogger(__name__)
cache_meta = None
def includeme(config):
d-cache: don't init in includeme so we don't trigger s3 connections on startup of rcstack....
r5487 return # don't init cache currently for faster startup time
feat(archive-cache): implemented s3 based backend for filecaches
r5433 # init our cache at start
d-cache: don't init in includeme so we don't trigger s3 connections on startup of rcstack....
r5487 # settings = config.get_settings()
# get_archival_cache_store(settings)
feat(archive-cache): implemented s3 based backend for filecaches
r5433
def get_archival_config(config):
final_config = {
}
for k, v in config.items():
if k.startswith('archive_cache'):
final_config[k] = v
return final_config
def get_archival_cache_store(config, always_init=False):
global cache_meta
if cache_meta is not None and not always_init:
return cache_meta
config = get_archival_config(config)
backend = config['archive_cache.backend.type']
archive_cache_locking_url = config['archive_cache.locking.url']
match backend:
case 'filesystem':
d_cache = FileSystemFanoutCache(
locking_url=archive_cache_locking_url,
**config
)
case 'objectstore':
d_cache = ObjectStoreCache(
locking_url=archive_cache_locking_url,
**config
)
case _:
raise ValueError(f'archive_cache.backend.type only supports "filesystem" or "objectstore" got {backend} ')
cache_meta = d_cache
return cache_meta