Mercurial > hg > orthanc
comparison OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5046:2b3b0ab88c1d
fix storage cache
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 29 Jun 2022 08:10:28 +0200 |
parents | 45d6ce72a84e |
children | 207f259c41c5 |
comparison
equal
deleted
inserted
replaced
5045:a9ca92ecbbc2 | 5046:2b3b0ab88c1d |
---|---|
154 | 154 |
155 | 155 |
156 void StorageAccessor::Read(std::string& content, | 156 void StorageAccessor::Read(std::string& content, |
157 const FileInfo& info) | 157 const FileInfo& info) |
158 { | 158 { |
159 switch (info.GetCompressionType()) | 159 if (!cache_.Fetch(content, info.GetUuid(), info.GetContentType())) |
160 { | 160 { |
161 case CompressionType_None: | 161 switch (info.GetCompressionType()) |
162 { | 162 { |
163 if (!cache_.Fetch(content, info.GetUuid(), info.GetContentType())) | 163 case CompressionType_None: |
164 { | 164 { |
165 MetricsTimer timer(*this, METRICS_READ); | 165 MetricsTimer timer(*this, METRICS_READ); |
166 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); | 166 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); |
167 buffer->MoveToString(content); | 167 buffer->MoveToString(content); |
168 } | 168 |
169 | 169 break; |
170 break; | 170 } |
171 } | 171 |
172 | 172 case CompressionType_ZlibWithSize: |
173 case CompressionType_ZlibWithSize: | 173 { |
174 { | 174 ZlibCompressor zlib; |
175 ZlibCompressor zlib; | 175 |
176 | |
177 std::string cached; | |
178 if (cache_.Fetch(cached, info.GetUuid(), info.GetContentType())) | |
179 { | |
180 zlib.Uncompress(content, cached.empty() ? NULL : cached.c_str(), cached.size()); | |
181 } | |
182 else | |
183 { | |
184 std::unique_ptr<IMemoryBuffer> compressed; | 176 std::unique_ptr<IMemoryBuffer> compressed; |
185 | 177 |
186 { | 178 { |
187 MetricsTimer timer(*this, METRICS_READ); | 179 MetricsTimer timer(*this, METRICS_READ); |
188 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType())); | 180 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType())); |
189 } | 181 } |
190 | 182 |
191 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize()); | 183 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize()); |
192 } | 184 |
193 | 185 break; |
194 break; | 186 } |
187 | |
188 default: | |
189 { | |
190 throw OrthancException(ErrorCode_NotImplemented); | |
191 } | |
195 } | 192 } |
196 | 193 |
197 default: | 194 // always store the uncompressed data in cache |
198 { | 195 cache_.Add(info.GetUuid(), info.GetContentType(), content); |
199 throw OrthancException(ErrorCode_NotImplemented); | |
200 } | |
201 } | 196 } |
202 | 197 |
203 // TODO Check the validity of the uncompressed MD5? | 198 // TODO Check the validity of the uncompressed MD5? |
204 } | 199 } |
205 | 200 |