# HG changeset patch # User Sebastien Jodogne # Date 1424966137 -3600 # Node ID ecefd45026bf9b8e60450a676b0cf386920dace7 # Parent ca16691db433d0dad16c1f98d8c64a69c6e7b54d configuration of the cache diff -r ca16691db433 -r ecefd45026bf Plugin/Cache/CacheScheduler.cpp --- a/Plugin/Cache/CacheScheduler.cpp Thu Feb 26 11:39:28 2015 +0100 +++ b/Plugin/Cache/CacheScheduler.cpp Thu Feb 26 16:55:37 2015 +0100 @@ -300,6 +300,15 @@ } + void CacheScheduler::SetQuota(int bundle, + uint32_t maxCount, + uint64_t maxSpace) + { + boost::mutex::scoped_lock lock(cacheMutex_); + cache_.SetBundleQuota(bundle, maxCount, maxSpace); + } + + void CacheScheduler::Invalidate(int bundle, const std::string& item) { diff -r ca16691db433 -r ecefd45026bf Plugin/Cache/CacheScheduler.h --- a/Plugin/Cache/CacheScheduler.h Thu Feb 26 11:39:28 2015 +0100 +++ b/Plugin/Cache/CacheScheduler.h Thu Feb 26 16:55:37 2015 +0100 @@ -64,6 +64,10 @@ ICacheFactory* factory /* takes ownership */, size_t numThreads); + void SetQuota(int bundle, + uint32_t maxCount, + uint64_t maxSpace); + void RegisterPolicy(IPrefetchPolicy* policy /* takes ownership */); void Invalidate(int bundle, diff -r ca16691db433 -r ecefd45026bf Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Thu Feb 26 11:39:28 2015 +0100 +++ b/Plugin/Plugin.cpp Thu Feb 26 16:55:37 2015 +0100 @@ -21,6 +21,7 @@ #include #include #include +#include #include "../Orthanc/OrthancException.h" #include "ViewerToolbox.h" @@ -259,11 +260,23 @@ return -1; } - std::string cachePath = "WebViewerCache"; - + // By default, the cache of the Web viewer is located inside the + // "StorageDirectory" of Orthanc + boost::filesystem::path cachePath = GetStringValue(configuration, "StorageDirectory", "."); + cachePath /= "WebViewerCache"; + int cacheSize = 100; // By default, a cache of 100 MB is used + if (configuration.isMember("WebViewer")) { - cachePath = GetStringValue(configuration["WebViewer"], "Cache", cachePath); + std::string key = "CachePath"; + if (!configuration["WebViewer"].isMember(key)) + { + // For backward compatibility with the initial release of the Web viewer + key = "Cache"; + } + + cachePath = GetStringValue(configuration["WebViewer"], key, cachePath.string()); + cacheSize = GetIntegerValue(configuration["WebViewer"], "CacheSize", cacheSize); decodingThreads = GetIntegerValue(configuration["WebViewer"], "Threads", decodingThreads); } @@ -271,17 +284,18 @@ " threads for the decoding of the DICOM images"); OrthancPluginLogWarning(context_, message.c_str()); - if (decodingThreads <= 0) + if (decodingThreads <= 0 || + cacheSize <= 0) { throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } - message = "Storing the cache of the Web viewer in folder: " + cachePath; + message = "Storing the cache of the Web viewer in folder: " + cachePath.string(); OrthancPluginLogWarning(context_, message.c_str()); /* Create the cache */ - cache_ = new CacheContext(cachePath); + cache_ = new CacheContext(cachePath.string()); cache_->GetScheduler().RegisterPolicy(new ViewerPrefetchPolicy(context_)); cache_->GetScheduler().Register(CacheBundle_SeriesInformation, new SeriesInformationAdapter(context_, cache_->GetScheduler()), 1); @@ -289,6 +303,16 @@ new InstanceInformationAdapter(context_), 1); cache_->GetScheduler().Register(CacheBundle_DecodedImage, new DecodedImageAdapter(context_), decodingThreads); + + + /* Set the quotas */ + cache_->GetScheduler().SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series + cache_->GetScheduler().SetQuota(CacheBundle_InstanceInformation, 10000, 0); // Keep info about 10,000 instances + + message = "Web viewer using a cache of " + boost::lexical_cast(cacheSize) + " MB"; + OrthancPluginLogWarning(context_, message.c_str()); + + cache_->GetScheduler().SetQuota(CacheBundle_DecodedImage, 0, static_cast(cacheSize) * 1024 * 1024); } catch (std::runtime_error& e) { diff -r ca16691db433 -r ecefd45026bf WebApplication/viewer.js --- a/WebApplication/viewer.js Thu Feb 26 11:39:28 2015 +0100 +++ b/WebApplication/viewer.js Thu Feb 26 16:55:37 2015 +0100 @@ -21,7 +21,6 @@ var compression = 'jpeg95'; - // Prevent the access to IE if(navigator.appVersion.indexOf("MSIE ") != -1) {