# HG changeset patch
# User Goffi <goffi@goffi.org>
# Date 1521011155 -3600
# Node ID cd7a53c31eb6067bc67dc8d2e55750f8956a6230
# Parent  842bd1594077861b95ca25f87ce4fe216b805533
core (memory/cache): new getMetadata method to retrieve metadata without opening the file

diff -r 842bd1594077 -r cd7a53c31eb6 src/memory/cache.py
--- a/src/memory/cache.py	Wed Mar 14 07:57:04 2018 +0100
+++ b/src/memory/cache.py	Wed Mar 14 08:05:55 2018 +0100
@@ -59,13 +59,15 @@
             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 @@
                 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