comparison OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 4906:f656fb878b50

reintroduced storage cache for StartRange files
author Alain Mazy <am@osimis.io>
date Mon, 21 Feb 2022 10:11:38 +0100
parents 0bb73ef7cf07
children 45d6ce72a84e
comparison
equal deleted inserted replaced
4902:df86d2505df8 4906:f656fb878b50
237 void StorageAccessor::ReadStartRange(std::string& target, 237 void StorageAccessor::ReadStartRange(std::string& target,
238 const std::string& fileUuid, 238 const std::string& fileUuid,
239 FileContentType contentType, 239 FileContentType contentType,
240 uint64_t end /* exclusive */) 240 uint64_t end /* exclusive */)
241 { 241 {
242 if (cache_.Fetch(target, fileUuid, contentType)) 242 if (cache_.FetchStartRange(target, fileUuid, contentType, end))
243 { 243 {
244 if (target.size() < end) 244 return;
245 {
246 throw OrthancException(ErrorCode_CorruptedFile);
247 }
248 else
249 {
250 target.resize(end);
251 }
252 } 245 }
253 else 246 else
254 { 247 {
255 MetricsTimer timer(*this, METRICS_READ); 248 MetricsTimer timer(*this, METRICS_READ);
256 std::unique_ptr<IMemoryBuffer> buffer(area_.ReadRange(fileUuid, contentType, 0, end)); 249 std::unique_ptr<IMemoryBuffer> buffer(area_.ReadRange(fileUuid, contentType, 0, end));
257 assert(buffer->GetSize() == end); 250 assert(buffer->GetSize() == end);
258 buffer->MoveToString(target); 251 buffer->MoveToString(target);
252
253 cache_.AddStartRange(fileUuid, contentType, target);
259 } 254 }
260 } 255 }
261 256
262 257
263 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1 258 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
268 if (!cache_.Fetch(sender.GetBuffer(), info.GetUuid(), info.GetContentType())) 263 if (!cache_.Fetch(sender.GetBuffer(), info.GetUuid(), info.GetContentType()))
269 { 264 {
270 MetricsTimer timer(*this, METRICS_READ); 265 MetricsTimer timer(*this, METRICS_READ);
271 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType())); 266 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType()));
272 buffer->MoveToString(sender.GetBuffer()); 267 buffer->MoveToString(sender.GetBuffer());
268
269 cache_.Add(info.GetUuid(), info.GetContentType(), sender.GetBuffer());
273 } 270 }
274 271
275 sender.SetContentType(mime); 272 sender.SetContentType(mime);
276 273
277 const char* extension; 274 const char* extension;