annotate ViewerPlugin/DicomPyramidCache.cpp @ 194:e57e6ca5303d

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 18:03:23 +0200
parents e3cbf890b588
children b0bd22077cd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
175
e3cbf890b588 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "../Framework/PrecompiledHeadersWSI.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "DicomPyramidCache.h"
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <cassert>
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 namespace OrthancWSI
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 DicomPyramid* DicomPyramidCache::GetCachedPyramid(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 // Is the series of interest already cached as a pyramid?
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 if (cache_.Contains(seriesId, pyramid))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (pyramid == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 // Tag the series as the most recently used
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 cache_.MakeMostRecent(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 return pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 DicomPyramid& DicomPyramidCache::GetPyramid(const std::string& seriesId,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 boost::mutex::scoped_lock& lock)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 // Mutex is assumed to be locked
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DicomPyramid* pyramid = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 return *pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 // Unlock the mutex to construct the pyramid (this is a
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 // time-consuming operation, we don't want it to block other clients)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 lock.unlock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 std::auto_ptr<DicomPyramid> pyramid
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 (new DicomPyramid(orthanc_, seriesId, true /* use metadata cache */));
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 // The pyramid is constructed: Store it into the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 lock.lock();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 DicomPyramid* cached = GetCachedPyramid(seriesId);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if (cached != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 // The pyramid was already constructed by another request in
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 // between, reuse the cached value (the auto_ptr destroys
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 // the just-constructed pyramid)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 return *cached;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (cache_.GetSize() == maxSize_)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 // The cache has grown too large: First delete the least
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 DicomPyramid* oldest = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 cache_.RemoveOldest(oldest);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if (oldest == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 else
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 delete oldest;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 // Now we have at least one free entry in the cache
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 assert(cache_.GetSize() < maxSize_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 // Add a new element to the cache and make it the most
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 // recently used entry
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 DicomPyramid* payload = pyramid.release();
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 cache_.Add(seriesId, payload);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return *payload;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 DicomPyramidCache::DicomPyramidCache(OrthancPlugins::IOrthancConnection& orthanc,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 size_t maxSize) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 orthanc_(orthanc),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 maxSize_(maxSize)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 DicomPyramidCache::~DicomPyramidCache()
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 while (!cache_.IsEmpty())
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 DicomPyramid* pyramid = NULL;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 std::string seriesId = cache_.RemoveOldest(pyramid);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (pyramid != NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 delete pyramid;
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 void DicomPyramidCache::Invalidate(const std::string& seriesId)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 boost::mutex::scoped_lock lock(mutex_);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (cache_.Contains(seriesId))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 std::auto_ptr<DicomPyramid> pyramid(cache_.Invalidate(seriesId));
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 if (pyramid.get() == NULL)
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 DicomPyramidCache::Locker::Locker(DicomPyramidCache& cache,
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 const std::string& seriesId) :
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 lock_(cache.mutex_),
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 pyramid_(cache.GetPyramid(seriesId, lock_))
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
a8c90aa32ca6 LRU caching of pyramids, OrthancWSIClearCache script
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }