core (memory/cache): new getMetadata method to retrieve metadata without opening the file

This commit is contained in:
Goffi 2018-03-14 08:05:55 +01:00
commit 41ce2e27e6

View file

@ -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