##// END OF EJS Templates
d-cache: don't init in includeme so we don't trigger s3 connections on startup of rcstack....
super-admin -
r5487:c594e70d default
parent child Browse files
Show More
@@ -1,78 +1,80 b''
1 # Copyright (C) 2015-2024 RhodeCode GmbH
1 # Copyright (C) 2015-2024 RhodeCode GmbH
2 #
2 #
3 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU Affero General Public License, version 3
4 # it under the terms of the GNU Affero General Public License, version 3
5 # (only), as published by the Free Software Foundation.
5 # (only), as published by the Free Software Foundation.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU Affero General Public License
12 # You should have received a copy of the GNU Affero General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #
14 #
15 # This program is dual-licensed. If you wish to learn more about the
15 # This program is dual-licensed. If you wish to learn more about the
16 # RhodeCode Enterprise Edition, including its added features, Support services,
16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 import logging
19 import logging
20
20
21 from .backends.fanout_cache import FileSystemFanoutCache
21 from .backends.fanout_cache import FileSystemFanoutCache
22 from .backends.objectstore_cache import ObjectStoreCache
22 from .backends.objectstore_cache import ObjectStoreCache
23
23
24 from .utils import archive_iterator # noqa
24 from .utils import archive_iterator # noqa
25 from .lock import ArchiveCacheGenerationLock # noqa
25 from .lock import ArchiveCacheGenerationLock # noqa
26
26
27 log = logging.getLogger(__name__)
27 log = logging.getLogger(__name__)
28
28
29
29
30 cache_meta = None
30 cache_meta = None
31
31
32
32
33 def includeme(config):
33 def includeme(config):
34 return # don't init cache currently for faster startup time
35
34 # init our cache at start
36 # init our cache at start
35 settings = config.get_settings()
37 # settings = config.get_settings()
36 get_archival_cache_store(settings)
38 # get_archival_cache_store(settings)
37
39
38
40
39 def get_archival_config(config):
41 def get_archival_config(config):
40
42
41 final_config = {
43 final_config = {
42
44
43 }
45 }
44
46
45 for k, v in config.items():
47 for k, v in config.items():
46 if k.startswith('archive_cache'):
48 if k.startswith('archive_cache'):
47 final_config[k] = v
49 final_config[k] = v
48
50
49 return final_config
51 return final_config
50
52
51
53
52 def get_archival_cache_store(config, always_init=False):
54 def get_archival_cache_store(config, always_init=False):
53
55
54 global cache_meta
56 global cache_meta
55 if cache_meta is not None and not always_init:
57 if cache_meta is not None and not always_init:
56 return cache_meta
58 return cache_meta
57
59
58 config = get_archival_config(config)
60 config = get_archival_config(config)
59 backend = config['archive_cache.backend.type']
61 backend = config['archive_cache.backend.type']
60
62
61 archive_cache_locking_url = config['archive_cache.locking.url']
63 archive_cache_locking_url = config['archive_cache.locking.url']
62
64
63 match backend:
65 match backend:
64 case 'filesystem':
66 case 'filesystem':
65 d_cache = FileSystemFanoutCache(
67 d_cache = FileSystemFanoutCache(
66 locking_url=archive_cache_locking_url,
68 locking_url=archive_cache_locking_url,
67 **config
69 **config
68 )
70 )
69 case 'objectstore':
71 case 'objectstore':
70 d_cache = ObjectStoreCache(
72 d_cache = ObjectStoreCache(
71 locking_url=archive_cache_locking_url,
73 locking_url=archive_cache_locking_url,
72 **config
74 **config
73 )
75 )
74 case _:
76 case _:
75 raise ValueError(f'archive_cache.backend.type only supports "filesystem" or "objectstore" got {backend} ')
77 raise ValueError(f'archive_cache.backend.type only supports "filesystem" or "objectstore" got {backend} ')
76
78
77 cache_meta = d_cache
79 cache_meta = d_cache
78 return cache_meta
80 return cache_meta
General Comments 0
You need to be logged in to leave comments. Login now