Show More
@@ -247,7 +247,7 b' class BaseCache:' | |||||
247 | def get_lock(self, lock_key): |
|
247 | def get_lock(self, lock_key): | |
248 | return GenerationLock(lock_key, self._locking_url) |
|
248 | return GenerationLock(lock_key, self._locking_url) | |
249 |
|
249 | |||
250 |
def evict(self, policy=None, size_limit=None) -> |
|
250 | def evict(self, policy=None, size_limit=None) -> dict: | |
251 | """ |
|
251 | """ | |
252 | Remove old items based on the conditions |
|
252 | Remove old items based on the conditions | |
253 |
|
253 | |||
@@ -257,13 +257,16 b' class BaseCache:' | |||||
257 | read the key files metadata stored. This gives us a full list of keys, cached_archived, their size and |
|
257 | read the key files metadata stored. This gives us a full list of keys, cached_archived, their size and | |
258 | access data, time creation, and access counts. |
|
258 | access data, time creation, and access counts. | |
259 |
|
259 | |||
260 |
Store that into a memory DB |
|
260 | Store that into a memory DB in order we can run different sorting strategies easily. | |
261 | Summing the size is a sum sql query. |
|
261 | Summing the size is a sum sql query. | |
262 |
|
262 | |||
263 | Then we run a sorting strategy based on eviction policy. |
|
263 | Then we run a sorting strategy based on eviction policy. | |
264 | We iterate over sorted keys, and remove each checking if we hit the overall limit. |
|
264 | We iterate over sorted keys, and remove each checking if we hit the overall limit. | |
265 | """ |
|
265 | """ | |
266 |
|
266 | removal_info = { | ||
|
267 | "removed_items": 0, | |||
|
268 | "removed_size": 0 | |||
|
269 | } | |||
267 | policy = policy or self._eviction_policy |
|
270 | policy = policy or self._eviction_policy | |
268 | size_limit = size_limit or self._cache_size_limit |
|
271 | size_limit = size_limit or self._cache_size_limit | |
269 |
|
272 | |||
@@ -273,7 +276,7 b' class BaseCache:' | |||||
273 | policy, format_size(size_limit)) |
|
276 | policy, format_size(size_limit)) | |
274 |
|
277 | |||
275 | if select_policy is None: |
|
278 | if select_policy is None: | |
276 |
return |
|
279 | return removal_info | |
277 |
|
280 | |||
278 | db = self.get_stats_db() |
|
281 | db = self.get_stats_db() | |
279 |
|
282 | |||
@@ -327,10 +330,11 b' class BaseCache:' | |||||
327 | self.remove(archive_key) |
|
330 | self.remove(archive_key) | |
328 | removed_items += 1 |
|
331 | removed_items += 1 | |
329 | removed_size += size |
|
332 | removed_size += size | |
330 |
|
333 | removal_info['removed_items'] = removed_items | ||
|
334 | removal_info['removed_size'] = removed_size | |||
331 | log.debug('Removed %s cache archives, and reduced size by: %s', |
|
335 | log.debug('Removed %s cache archives, and reduced size by: %s', | |
332 | removed_items, format_size(removed_size)) |
|
336 | removed_items, format_size(removed_size)) | |
333 |
return remov |
|
337 | return removal_info | |
334 |
|
338 | |||
335 | def get_statistics(self): |
|
339 | def get_statistics(self): | |
336 | total_files = 0 |
|
340 | total_files = 0 |
General Comments 0
You need to be logged in to leave comments.
Login now