comparison OrthancFramework/Sources/FileStorage/StorageCache.cpp @ 4826:6c276fac0cc0

fix storage cache for user attachment -> the cache is ignoring them
author Alain Mazy <am@osimis.io>
date Thu, 25 Nov 2021 15:36:11 +0100
parents 434843934307
children 7053502fbf97
comparison
equal deleted inserted replaced
4825:381c2ca04860 4826:6c276fac0cc0
51 throw OrthancException(ErrorCode_InternalError, 51 throw OrthancException(ErrorCode_InternalError,
52 "ContentType not supported in StorageCache"); 52 "ContentType not supported in StorageCache");
53 } 53 }
54 } 54 }
55 55
56 void GetCacheKey(std::string& key, const std::string& uuid, FileContentType contentType) 56 bool GetCacheKey(std::string& key, const std::string& uuid, FileContentType contentType)
57 { 57 {
58 if (contentType == FileContentType_Unknown || contentType >= FileContentType_StartUser)
59 {
60 return false;
61 }
62
58 key = uuid + ":" + std::string(ToString(contentType)); 63 key = uuid + ":" + std::string(ToString(contentType));
64
65 return true;
59 } 66 }
60 67
61 void StorageCache::SetMaximumSize(size_t size) 68 void StorageCache::SetMaximumSize(size_t size)
62 { 69 {
63 cache_.SetMaximumSize(size); 70 cache_.SetMaximumSize(size);
71 { 78 {
72 return; 79 return;
73 } 80 }
74 81
75 std::string key; 82 std::string key;
76 GetCacheKey(key, uuid, contentType); 83
77 cache_.Add(key, value); 84 if (GetCacheKey(key, uuid, contentType))
85 {
86 cache_.Add(key, value);
87 }
78 } 88 }
79 89
80 void StorageCache::Add(const std::string& uuid, 90 void StorageCache::Add(const std::string& uuid,
81 FileContentType contentType, 91 FileContentType contentType,
82 const void* buffer, 92 const void* buffer,
86 { 96 {
87 return; 97 return;
88 } 98 }
89 99
90 std::string key; 100 std::string key;
91 GetCacheKey(key, uuid, contentType); 101
92 cache_.Add(key, buffer, size); 102 if (GetCacheKey(key, uuid, contentType))
103 {
104 cache_.Add(key, buffer, size);
105 }
93 } 106 }
94 107
95 void StorageCache::Invalidate(const std::string& uuid, FileContentType contentType) 108 void StorageCache::Invalidate(const std::string& uuid, FileContentType contentType)
96 { 109 {
97 std::string key; 110 std::string key;
98 GetCacheKey(key, uuid, contentType); 111
99 cache_.Invalidate(key); 112 if (GetCacheKey(key, uuid, contentType))
113 {
114 cache_.Invalidate(key);
115 }
100 } 116 }
101 117
102 bool StorageCache::Fetch(std::string& value, 118 bool StorageCache::Fetch(std::string& value,
103 const std::string& uuid, 119 const std::string& uuid,
104 FileContentType contentType) 120 FileContentType contentType)
107 { 123 {
108 return false; 124 return false;
109 } 125 }
110 126
111 std::string key; 127 std::string key;
112 GetCacheKey(key, uuid, contentType); 128 if (GetCacheKey(key, uuid, contentType))
129 {
130 return cache_.Fetch(value, key);
131 }
113 132
114 return cache_.Fetch(value, key); 133 return false;
115 } 134 }
116 135
117 136
118 } 137 }