# HG changeset patch # User Goffi # Date 1583515143 -3600 # Node ID fedec192a83f0bcda03a59986137cd5421c0f8cf # Parent f14eb24328d076f286fe5f4949864f8383487cb8 core (memory/cache): new removeFromCache method diff -r f14eb24328d0 -r fedec192a83f sat/memory/cache.py --- a/sat/memory/cache.py Fri Mar 06 18:19:03 2020 +0100 +++ b/sat/memory/cache.py Fri Mar 06 18:19:03 2020 +0100 @@ -184,6 +184,34 @@ if metadata is not None: 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): """create cache metadata and file object to use for actual data