Show More
@@ -78,10 +78,13 b' class FileSystemCache:' | |||||
78 | # STORE METADATA |
|
78 | # STORE METADATA | |
79 | _metadata = { |
|
79 | _metadata = { | |
80 | "version": "v1", |
|
80 | "version": "v1", | |
81 | "timestamp": time.time(), |
|
|||
82 | "filename": filename, |
|
81 | "filename": filename, | |
83 | "full_path": full_path, |
|
82 | "full_path": full_path, | |
84 | "key_file": key_file, |
|
83 | "key_file": key_file, | |
|
84 | "store_time": time.time(), | |||
|
85 | "access_count": 1, | |||
|
86 | "access_time": 0, | |||
|
87 | "size": 0 | |||
85 | } |
|
88 | } | |
86 | if metadata: |
|
89 | if metadata: | |
87 | _metadata.update(metadata) |
|
90 | _metadata.update(metadata) | |
@@ -90,6 +93,7 b' class FileSystemCache:' | |||||
90 |
|
93 | |||
91 | iterator = iter(reader, b'') |
|
94 | iterator = iter(reader, b'') | |
92 | size = self._write_file(full_path, iterator, 'xb') |
|
95 | size = self._write_file(full_path, iterator, 'xb') | |
|
96 | metadata['size'] = size | |||
93 |
|
97 | |||
94 | # after archive is finished, we create a key to save the presence of the binary file |
|
98 | # after archive is finished, we create a key to save the presence of the binary file | |
95 | with open(key_file, 'wb') as f: |
|
99 | with open(key_file, 'wb') as f: | |
@@ -107,7 +111,15 b' class FileSystemCache:' | |||||
107 |
|
111 | |||
108 | filename = metadata['filename'] |
|
112 | filename = metadata['filename'] | |
109 |
|
113 | |||
110 | return open(os.path.join(self._directory, filename), 'rb'), metadata |
|
114 | try: | |
|
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 | def random_filename(self): |
|
124 | def random_filename(self): | |
113 | """Return filename and full-path tuple for file storage. |
|
125 | """Return filename and full-path tuple for file storage. | |
@@ -169,6 +181,9 b' class FanoutCache:' | |||||
169 | self._count = settings.pop('cache_shards') |
|
181 | self._count = settings.pop('cache_shards') | |
170 | self._locking_url = settings.pop('locking_url') |
|
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 | self._shards = tuple( |
|
187 | self._shards = tuple( | |
173 | FileSystemCache( |
|
188 | FileSystemCache( | |
174 | index=num, |
|
189 | index=num, | |
@@ -261,4 +276,3 b' def get_archival_cache_store(config):' | |||||
261 | ) |
|
276 | ) | |
262 | cache_meta = d_cache |
|
277 | cache_meta = d_cache | |
263 | return cache_meta |
|
278 | return cache_meta | |
264 |
|
@@ -15,6 +15,7 b'' | |||||
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 | import os |
|
19 | import os | |
19 |
|
20 | |||
20 |
|
21 |
General Comments 0
You need to be logged in to leave comments.
Login now