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 | |
|
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 | 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 |
General Comments 0
You need to be logged in to leave comments.
Login now