comparison Plugin/Plugin.cpp @ 4:ecefd45026bf

configuration of the cache
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Feb 2015 16:55:37 +0100
parents 02f7a0400a91
children 379131283479
comparison
equal deleted inserted replaced
3:ca16691db433 4:ecefd45026bf
19 19
20 20
21 #include <boost/thread.hpp> 21 #include <boost/thread.hpp>
22 #include <boost/lexical_cast.hpp> 22 #include <boost/lexical_cast.hpp>
23 #include <EmbeddedResources.h> 23 #include <EmbeddedResources.h>
24 #include <boost/filesystem.hpp>
24 25
25 #include "../Orthanc/OrthancException.h" 26 #include "../Orthanc/OrthancException.h"
26 #include "ViewerToolbox.h" 27 #include "ViewerToolbox.h"
27 #include "ViewerPrefetchPolicy.h" 28 #include "ViewerPrefetchPolicy.h"
28 #include "DecodedImageAdapter.h" 29 #include "DecodedImageAdapter.h"
257 { 258 {
258 OrthancPluginLogError(context_, "Unable to read the configuration file of Orthanc"); 259 OrthancPluginLogError(context_, "Unable to read the configuration file of Orthanc");
259 return -1; 260 return -1;
260 } 261 }
261 262
262 std::string cachePath = "WebViewerCache"; 263 // By default, the cache of the Web viewer is located inside the
263 264 // "StorageDirectory" of Orthanc
265 boost::filesystem::path cachePath = GetStringValue(configuration, "StorageDirectory", ".");
266 cachePath /= "WebViewerCache";
267 int cacheSize = 100; // By default, a cache of 100 MB is used
268
264 if (configuration.isMember("WebViewer")) 269 if (configuration.isMember("WebViewer"))
265 { 270 {
266 cachePath = GetStringValue(configuration["WebViewer"], "Cache", cachePath); 271 std::string key = "CachePath";
272 if (!configuration["WebViewer"].isMember(key))
273 {
274 // For backward compatibility with the initial release of the Web viewer
275 key = "Cache";
276 }
277
278 cachePath = GetStringValue(configuration["WebViewer"], key, cachePath.string());
279 cacheSize = GetIntegerValue(configuration["WebViewer"], "CacheSize", cacheSize);
267 decodingThreads = GetIntegerValue(configuration["WebViewer"], "Threads", decodingThreads); 280 decodingThreads = GetIntegerValue(configuration["WebViewer"], "Threads", decodingThreads);
268 } 281 }
269 282
270 std::string message = ("Web viewer using " + boost::lexical_cast<std::string>(decodingThreads) + 283 std::string message = ("Web viewer using " + boost::lexical_cast<std::string>(decodingThreads) +
271 " threads for the decoding of the DICOM images"); 284 " threads for the decoding of the DICOM images");
272 OrthancPluginLogWarning(context_, message.c_str()); 285 OrthancPluginLogWarning(context_, message.c_str());
273 286
274 if (decodingThreads <= 0) 287 if (decodingThreads <= 0 ||
288 cacheSize <= 0)
275 { 289 {
276 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 290 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
277 } 291 }
278 292
279 message = "Storing the cache of the Web viewer in folder: " + cachePath; 293 message = "Storing the cache of the Web viewer in folder: " + cachePath.string();
280 OrthancPluginLogWarning(context_, message.c_str()); 294 OrthancPluginLogWarning(context_, message.c_str());
281 295
282 296
283 /* Create the cache */ 297 /* Create the cache */
284 cache_ = new CacheContext(cachePath); 298 cache_ = new CacheContext(cachePath.string());
285 cache_->GetScheduler().RegisterPolicy(new ViewerPrefetchPolicy(context_)); 299 cache_->GetScheduler().RegisterPolicy(new ViewerPrefetchPolicy(context_));
286 cache_->GetScheduler().Register(CacheBundle_SeriesInformation, 300 cache_->GetScheduler().Register(CacheBundle_SeriesInformation,
287 new SeriesInformationAdapter(context_, cache_->GetScheduler()), 1); 301 new SeriesInformationAdapter(context_, cache_->GetScheduler()), 1);
288 cache_->GetScheduler().Register(CacheBundle_InstanceInformation, 302 cache_->GetScheduler().Register(CacheBundle_InstanceInformation,
289 new InstanceInformationAdapter(context_), 1); 303 new InstanceInformationAdapter(context_), 1);
290 cache_->GetScheduler().Register(CacheBundle_DecodedImage, 304 cache_->GetScheduler().Register(CacheBundle_DecodedImage,
291 new DecodedImageAdapter(context_), decodingThreads); 305 new DecodedImageAdapter(context_), decodingThreads);
306
307
308 /* Set the quotas */
309 cache_->GetScheduler().SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series
310 cache_->GetScheduler().SetQuota(CacheBundle_InstanceInformation, 10000, 0); // Keep info about 10,000 instances
311
312 message = "Web viewer using a cache of " + boost::lexical_cast<std::string>(cacheSize) + " MB";
313 OrthancPluginLogWarning(context_, message.c_str());
314
315 cache_->GetScheduler().SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024);
292 } 316 }
293 catch (std::runtime_error& e) 317 catch (std::runtime_error& e)
294 { 318 {
295 OrthancPluginLogError(context_, e.what()); 319 OrthancPluginLogError(context_, e.what());
296 return -1; 320 return -1;