comparison Plugin/Plugin.cpp @ 115:c8ca47a67bf3

automatic clearing of the cache
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Dec 2015 17:08:51 +0100
parents 628697fdfcbd
children 3809121c3290
comparison
equal deleted inserted replaced
114:628697fdfcbd 115:c8ca47a67bf3
446 OrthancPluginLogWarning(context_, message.c_str()); 446 OrthancPluginLogWarning(context_, message.c_str());
447 447
448 448
449 /* Create the cache */ 449 /* Create the cache */
450 cache_ = new CacheContext(cachePath.string()); 450 cache_ = new CacheContext(cachePath.string());
451 cache_->GetScheduler().RegisterPolicy(new ViewerPrefetchPolicy(context_)); 451 CacheScheduler& scheduler = cache_->GetScheduler();
452 cache_->GetScheduler().Register(CacheBundle_SeriesInformation, 452
453 new SeriesInformationAdapter(context_, cache_->GetScheduler()), 1); 453
454 cache_->GetScheduler().Register(CacheBundle_DecodedImage, 454 /* Look for a change in the versions */
455 new DecodedImageAdapter(context_), decodingThreads); 455 std::string orthancVersion("unknown"), webViewerVersion("unknown");
456 bool clear = false;
457 if (!scheduler.LookupProperty(orthancVersion, CacheProperty_OrthancVersion) ||
458 orthancVersion != std::string(context_->orthancVersion))
459 {
460 std::string s = ("The version of Orthanc has changed from \"" + orthancVersion + "\" to \"" +
461 std::string(context_->orthancVersion) + "\": The cache of the Web viewer will be cleared");
462 OrthancPluginLogWarning(context_, s.c_str());
463 clear = true;
464 }
465
466 if (!scheduler.LookupProperty(webViewerVersion, CacheProperty_WebViewerVersion) ||
467 webViewerVersion != std::string(ORTHANC_WEBVIEWER_VERSION))
468 {
469 std::string s = ("The version of the Web viewer plugin has changed from \"" + webViewerVersion + "\" to \"" +
470 std::string(ORTHANC_WEBVIEWER_VERSION) + "\": The cache of the Web viewer will be cleared");
471 OrthancPluginLogWarning(context_, s.c_str());
472 clear = true;
473 }
474
475
476 /* Clear the cache if needed */
477 if (clear)
478 {
479 OrthancPluginLogWarning(context_, "Clearing the cache of the Web viewer");
480 scheduler.Clear();
481 scheduler.SetProperty(CacheProperty_OrthancVersion, context_->orthancVersion);
482 scheduler.SetProperty(CacheProperty_WebViewerVersion, ORTHANC_WEBVIEWER_VERSION);
483 }
484 else
485 {
486 OrthancPluginLogInfo(context_, "No change in the versions, no need to clear the cache of the Web viewer");
487 }
488
489
490 /* Configure the cache */
491 scheduler.RegisterPolicy(new ViewerPrefetchPolicy(context_));
492 scheduler.Register(CacheBundle_SeriesInformation,
493 new SeriesInformationAdapter(context_, scheduler), 1);
494 scheduler.Register(CacheBundle_DecodedImage,
495 new DecodedImageAdapter(context_), decodingThreads);
456 496
457 497
458 /* Set the quotas */ 498 /* Set the quotas */
459 cache_->GetScheduler().SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series 499 scheduler.SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series
460 500
461 message = "Web viewer using a cache of " + boost::lexical_cast<std::string>(cacheSize) + " MB"; 501 message = "Web viewer using a cache of " + boost::lexical_cast<std::string>(cacheSize) + " MB";
462 OrthancPluginLogWarning(context_, message.c_str()); 502 OrthancPluginLogWarning(context_, message.c_str());
463 503
464 cache_->GetScheduler().SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024); 504 scheduler.SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024);
465 } 505 }
466 catch (std::runtime_error& e) 506 catch (std::runtime_error& e)
467 { 507 {
468 OrthancPluginLogError(context_, e.what()); 508 OrthancPluginLogError(context_, e.what());
469 return -1; 509 return -1;