diff --git a/SAS/DataManagement/StorageQueryService/cache.py b/SAS/DataManagement/StorageQueryService/cache.py index cb5ee357e068a10a091a54ace72770bbbf214e19..ac6633a765bb964db0f86fb6ed358d76707921ee 100644 --- a/SAS/DataManagement/StorageQueryService/cache.py +++ b/SAS/DataManagement/StorageQueryService/cache.py @@ -128,7 +128,7 @@ class CacheManager: # Furthermore, once a deeper level du results is stored in the memory cache, then it is also available for fast lookup. # We just don't store these deep levels on disk. sub_cache = { path:du_result for path,du_result in self._cache['path_du_results'].items() - if self.getDepthToProjectsDir(path) <= 1 } + if self.getDepthToProjectsDir(path) <= 1 and du_result.get('found') } cache_str = str(sub_cache) with open(tmp_path, 'w') as file: @@ -154,24 +154,24 @@ class CacheManager: if path in path_cache: otdb_id = du_result.get('otdb_id') - if du_result['found']: - if not path in path_cache or path_cache[path]['disk_usage'] != du_result['disk_usage']: - # update the cache entry, even when no du result found, - # cause that will save disk queries next time. - logger.info('updating cache entry: %s', du_result) - path_cache[path] = du_result + if not path in path_cache or path_cache[path]['disk_usage'] != du_result['disk_usage']: + # update the cache entry, even when no du result found, + # cause that will save disk queries next time. + logger.info('updating cache entry: %s', du_result) + path_cache[path] = du_result - path_cache[path]['cache_timestamp'] = datetime.datetime.utcnow() - path_cache[path]['needs_update'] = False + if otdb_id != None: + otdb_id2path_cache[otdb_id] = path - if otdb_id != None: - otdb_id2path_cache[otdb_id] = path - else: - if path in path_cache: - # no need to keep unknown path in cache - del path_cache[path] - if otdb_id != None and otdb_id in otdb_id2path_cache: - del otdb_id2path_cache[otdb_id] + if not du_result['found']: + # even when the du for the path is not found, + # keep a copy in the cache for fast lookup by clients + # Make sure the size is 0 + du_result['disk_usage'] = 0 + du_result['disk_usage_readable'] = humanreadablesize(0) + + path_cache[path]['cache_timestamp'] = datetime.datetime.utcnow() + path_cache[path]['needs_update'] = False self._writeCacheToDisk()