From 41ce2e27e6112870af9b901d68fb49d6dd24de05 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 14 Mar 2018 08:05:55 +0100 Subject: [PATCH] core (memory/cache): new getMetadata method to retrieve metadata without opening the file --- src/memory/cache.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/memory/cache.py b/src/memory/cache.py index d32eb1fe..39deac90 100644 --- a/src/memory/cache.py +++ b/src/memory/cache.py @@ -59,13 +59,15 @@ class Cache(object): raise exceptions.DataError(u"Invalid char found") return os.path.join(self.cache_dir, filename) - def getFilePath(self, uid): - """retrieve absolute path to file + def getMetadata(self, uid): + """retrieve metadata for cached data @param uid(unicode): unique identifier of file - @return (unicode, None): absolute path to cached file + @return (dict, None): metadata with following keys: + see [cacheData] for data details, an additional "path" key is the full path to cached file. None if file is not in cache (or cache is invalid) """ + uid = uid.strip() if not uid: raise exceptions.InternalError(u"uid must not be empty") @@ -93,7 +95,19 @@ class Cache(object): time.time() - eol)) return None - return self.getPath(cache_data['filename']) + cache_data['path'] = self.getPath(cache_data['filename']) + return cache_data + + def getFilePath(self, uid): + """retrieve absolute path to file + + @param uid(unicode): unique identifier of file + @return (unicode, None): absolute path to cached file + None if file is not in cache (or cache is invalid) + """ + metadata = self.getMetadata(uid) + if metadata is not None: + return metadata['path'] def cacheData(self, source, uid, mime_type=None, max_age=None, filename=None): """create cache metadata and file object to use for actual data