# HG changeset patch # User Sebastien Jodogne # Date 1637851986 -3600 # Node ID 2425fa7bd50db055b7ecebd50342398cdbae199a # Parent 4cfd9673207684c90608994acd6b98a83aa672c1# Parent 6c276fac0cc024d98f2120e2cd1c067141e98efd merge diff -r 4cfd96732076 -r 2425fa7bd50d OrthancFramework/Sources/FileStorage/StorageCache.cpp --- 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; }