core (memory/cache): new getMetadata method to retrieve metadata without opening the file
This commit is contained in:
parent
d51dc5b2eb
commit
41ce2e27e6
1 changed files with 18 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue