changeset 4828:2425fa7bd50d

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 15:53:06 +0100
parents 4cfd96732076 (current diff) 6c276fac0cc0 (diff)
children c847b0dfd255
files
diffstat 1 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/FileStorage/StorageCache.cpp	Thu Nov 25 15:52:54 2021 +0100
+++ b/OrthancFramework/Sources/FileStorage/StorageCache.cpp	Thu Nov 25 15:53:06 2021 +0100
@@ -53,9 +53,16 @@
     }
   }
 
-  void GetCacheKey(std::string& key, const std::string& uuid, FileContentType contentType)
+  bool GetCacheKey(std::string& key, const std::string& uuid, FileContentType contentType)
   {
+    if (contentType == FileContentType_Unknown || contentType >= FileContentType_StartUser)
+    {
+      return false;
+    }
+
     key = uuid + ":" + std::string(ToString(contentType));
+
+    return true;
   }
   
   void StorageCache::SetMaximumSize(size_t size)
@@ -73,8 +80,11 @@
     }
 
     std::string key;
-    GetCacheKey(key, uuid, contentType);
-    cache_.Add(key, value);
+
+    if (GetCacheKey(key, uuid, contentType))
+    {
+      cache_.Add(key, value);
+    }
   }
 
   void StorageCache::Add(const std::string& uuid, 
@@ -88,15 +98,21 @@
     }
     
     std::string key;
-    GetCacheKey(key, uuid, contentType);
-    cache_.Add(key, buffer, size);
+
+    if (GetCacheKey(key, uuid, contentType))
+    {
+      cache_.Add(key, buffer, size);
+    }
   }
 
   void StorageCache::Invalidate(const std::string& uuid, FileContentType contentType)
   {
     std::string key;
-    GetCacheKey(key, uuid, contentType);
-    cache_.Invalidate(key);
+    
+    if (GetCacheKey(key, uuid, contentType))
+    {
+      cache_.Invalidate(key);
+    }
   }
 
   bool StorageCache::Fetch(std::string& value, 
@@ -109,9 +125,12 @@
     }
 
     std::string key;
-    GetCacheKey(key, uuid, contentType);
+    if (GetCacheKey(key, uuid, contentType))
+    {
+      return cache_.Fetch(value, key);
+    }
 
-    return cache_.Fetch(value, key);
+    return false;
   }