##// END OF EJS Templates
feat(archive-cache): implement more usage stats for later easier evictions
super-admin -
r5422:386f3a63 default
parent child Browse files
Show More
@@ -78,10 +78,13 b' class FileSystemCache:'
78 78 # STORE METADATA
79 79 _metadata = {
80 80 "version": "v1",
81 "timestamp": time.time(),
82 81 "filename": filename,
83 82 "full_path": full_path,
84 83 "key_file": key_file,
84 "store_time": time.time(),
85 "access_count": 1,
86 "access_time": 0,
87 "size": 0
85 88 }
86 89 if metadata:
87 90 _metadata.update(metadata)
@@ -90,6 +93,7 b' class FileSystemCache:'
90 93
91 94 iterator = iter(reader, b'')
92 95 size = self._write_file(full_path, iterator, 'xb')
96 metadata['size'] = size
93 97
94 98 # after archive is finished, we create a key to save the presence of the binary file
95 99 with open(key_file, 'wb') as f:
@@ -107,7 +111,15 b' class FileSystemCache:'
107 111
108 112 filename = metadata['filename']
109 113
114 try:
110 115 return open(os.path.join(self._directory, filename), 'rb'), metadata
116 finally:
117 # update usage stats, count and accessed
118 metadata["access_count"] = metadata.get("access_count", 0) + 1
119 metadata["access_time"] = time.time()
120
121 with open(key_file, 'wb') as f:
122 f.write(json.dumps(metadata))
111 123
112 124 def random_filename(self):
113 125 """Return filename and full-path tuple for file storage.
@@ -169,6 +181,9 b' class FanoutCache:'
169 181 self._count = settings.pop('cache_shards')
170 182 self._locking_url = settings.pop('locking_url')
171 183
184 self._eviction_policy = settings['cache_eviction_policy']
185 self._cache_size_limit = settings['cache_size_limit']
186
172 187 self._shards = tuple(
173 188 FileSystemCache(
174 189 index=num,
@@ -261,4 +276,3 b' def get_archival_cache_store(config):'
261 276 )
262 277 cache_meta = d_cache
263 278 return cache_meta
264
@@ -15,6 +15,7 b''
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18 19 import os
19 20
20 21
General Comments 0
You need to be logged in to leave comments. Login now