core (memory/cache): new removeFromCache method
This commit is contained in:
parent
4b69d89138
commit
46a8728d7c
1 changed files with 28 additions and 0 deletions
|
|
@ -184,6 +184,34 @@ class Cache(object):
|
||||||
if metadata is not None:
|
if metadata is not None:
|
||||||
return metadata["path"]
|
return metadata["path"]
|
||||||
|
|
||||||
|
def removeFromCache(self, uid, metadata=None):
|
||||||
|
"""Remove data from cache
|
||||||
|
|
||||||
|
@param uid(unicode): unique identifier cache file
|
||||||
|
"""
|
||||||
|
cache_data = self.getMetadata(uid, update_eol=False)
|
||||||
|
if cache_data is None:
|
||||||
|
log.debug(f"cache with uid {uid!r} has already expired or been removed")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
filename = cache_data['filename']
|
||||||
|
except KeyError:
|
||||||
|
log.warning(_("missing filename for cache {uid!r}") .format(uid=uid))
|
||||||
|
else:
|
||||||
|
filepath = self.getPath(filename)
|
||||||
|
try:
|
||||||
|
filepath.unlink()
|
||||||
|
except FileNotFoundError:
|
||||||
|
log.warning(
|
||||||
|
_("missing file referenced in cache {uid!r}: {filename}")
|
||||||
|
.format(uid=uid, filename=filename)
|
||||||
|
)
|
||||||
|
|
||||||
|
cache_file = self.getPath(uid)
|
||||||
|
cache_file.unlink()
|
||||||
|
log.debug(f"cache with uid {uid!r} has been removed")
|
||||||
|
|
||||||
def cacheData(self, source, uid, mime_type=None, max_age=None, filename=None):
|
def cacheData(self, source, uid, mime_type=None, max_age=None, filename=None):
|
||||||
"""create cache metadata and file object to use for actual data
|
"""create cache metadata and file object to use for actual data
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue