Mercurial > hg > orthanc-webviewer
changeset 4:ecefd45026bf
configuration of the cache
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 26 Feb 2015 16:55:37 +0100 |
parents | ca16691db433 |
children | f6a16eb1f4c9 3a312d091947 |
files | Plugin/Cache/CacheScheduler.cpp Plugin/Cache/CacheScheduler.h Plugin/Plugin.cpp WebApplication/viewer.js |
diffstat | 4 files changed, 43 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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,
--- 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 <boost/thread.hpp> #include <boost/lexical_cast.hpp> #include <EmbeddedResources.h> +#include <boost/filesystem.hpp> #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<std::string>(cacheSize) + " MB"; + OrthancPluginLogWarning(context_, message.c_str()); + + cache_->GetScheduler().SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024); } catch (std::runtime_error& e) {