annotate OrthancFramework/Sources/Cache/LeastRecentlyUsedIndex.h @ 4934:94a7b681b340 more-tags

added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
author Alain Mazy <am@osimis.io>
date Thu, 10 Mar 2022 09:03:24 +0100
parents 43e613a7756b
children 0ea402b4d901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <list>
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <map>
3453
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
28 #include <vector>
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/noncopyable.hpp>
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
30 #include <cassert>
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
31
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
32 #include "../OrthancException.h"
284
06aa7b7b6723 implementation of a single-threaded cache mechanism
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 283
diff changeset
33 #include "../Toolbox.h"
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 * This class implements the index of a cache with least recently
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 * used (LRU) recycling policy. All the items of the cache index
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 * can be associated with a payload.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 * Reference: http://stackoverflow.com/a/2504317
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 template <typename T, typename Payload = NullType>
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
44 class LeastRecentlyUsedIndex : public boost::noncopyable
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 private:
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 typedef std::list< std::pair<T, Payload> > Queue;
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 typedef std::map<T, typename Queue::iterator> Index;
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 Index index_;
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 Queue queue_;
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 * Internal method for debug builds to check whether the internal
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 * data structures are not corrupted.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 void CheckInvariants() const;
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 public:
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 * Add a new element to the cache index, and make it the most
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 * recent element.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 * \param id The ID of the element.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 * \param payload The payload of the element.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 void Add(T id, Payload payload = Payload());
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
68 void AddOrMakeMostRecent(T id, Payload payload = Payload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
69
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 * When accessing an element of the cache, this method tags the
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 * element as the most recently used.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 * \param id The most recently accessed item.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 **/
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
75 void MakeMostRecent(T id);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
76
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
77 void MakeMostRecent(T id, Payload updatedPayload);
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 * Remove an element from the cache index.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 * \param id The item to remove.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 Payload Invalidate(T id);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 * Get the oldest element in the cache and remove it.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 * \return The oldest item.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 **/
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
89 T RemoveOldest();
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 * Get the oldest element in the cache, remove it and return the
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 * associated payload.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 * \param payload Where to store the associated payload.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 * \return The oldest item.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 T RemoveOldest(Payload& payload);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 * Check whether an element is contained in the cache.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 * \param id The item.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 * \return \c true iff the item is indexed by the cache.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 bool Contains(T id) const
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return index_.find(id) != index_.end();
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
109 bool Contains(T id, Payload& payload) const
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
110 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
111 typename Index::const_iterator it = index_.find(id);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
112 if (it == index_.end())
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
113 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
114 return false;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
115 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
116 else
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
117 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
118 payload = it->second->second;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
119 return true;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
120 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
121 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
122
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
123 /**
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
124 * Return the number of elements in the cache.
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
125 * \return The number of elements.
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
126 **/
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
127 size_t GetSize() const
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
128 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
129 assert(index_.size() == queue_.size());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
130 return queue_.size();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
131 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
132
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 /**
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 * Check whether the cache index is empty.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 * \return \c true iff the cache is empty.
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 **/
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 bool IsEmpty() const
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 return index_.empty();
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
141
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
142 const T& GetOldest() const;
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
143
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
144 const Payload& GetOldestPayload() const;
3453
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
145
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
146 void GetAllKeys(std::vector<T>& keys) const
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
147 {
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
148 keys.clear();
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
149 keys.reserve(GetSize());
4199
fbc49a65340a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
150 for (typename Index::const_iterator it = index_.begin(); it != index_.end(); ++it)
3453
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
151 {
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
152 keys.push_back(it->first);
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
153 }
8c663bbe5363 LeastRecentlyUsedIndex::GetAllKeys
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
154 }
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 };
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
156
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
157
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
158
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
159
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
160 /******************************************************************
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
161 ** Implementation of the template
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
162 ******************************************************************/
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
163
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
164 template <typename T, typename Payload>
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
165 void LeastRecentlyUsedIndex<T, Payload>::CheckInvariants() const
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
166 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
167 #ifndef NDEBUG
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
168 assert(index_.size() == queue_.size());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
169
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
170 for (typename Index::const_iterator
4199
fbc49a65340a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
171 it = index_.begin(); it != index_.end(); ++it)
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
172 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
173 assert(it->second != queue_.end());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
174 assert(it->second->first == it->first);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
175 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
176 #endif
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
177 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
178
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
179
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
180 template <typename T, typename Payload>
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
181 void LeastRecentlyUsedIndex<T, Payload>::Add(T id, Payload payload)
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
182 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
183 if (Contains(id))
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
184 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
185 throw OrthancException(ErrorCode_BadSequenceOfCalls);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
186 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
187
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
188 queue_.push_front(std::make_pair(id, payload));
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
189 index_[id] = queue_.begin();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
190
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
191 CheckInvariants();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
192 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
193
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
194
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
195 template <typename T, typename Payload>
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
196 void LeastRecentlyUsedIndex<T, Payload>::MakeMostRecent(T id)
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
197 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
198 if (!Contains(id))
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
199 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
200 throw OrthancException(ErrorCode_InexistentItem);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
201 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
202
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
203 typename Index::iterator it = index_.find(id);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
204 assert(it != index_.end());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
205
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
206 std::pair<T, Payload> item = *(it->second);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
207
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
208 queue_.erase(it->second);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
209 queue_.push_front(item);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
210 index_[id] = queue_.begin();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
211
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
212 CheckInvariants();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
213 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
214
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
215
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
216 template <typename T, typename Payload>
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
217 void LeastRecentlyUsedIndex<T, Payload>::AddOrMakeMostRecent(T id, Payload payload)
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
218 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
219 typename Index::iterator it = index_.find(id);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
220
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
221 if (it != index_.end())
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
222 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
223 // Already existing. Make it most recent.
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
224 std::pair<T, Payload> item = *(it->second);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
225 item.second = payload;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
226 queue_.erase(it->second);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
227 queue_.push_front(item);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
228 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
229 else
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
230 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
231 // New item
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
232 queue_.push_front(std::make_pair(id, payload));
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
233 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
234
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
235 index_[id] = queue_.begin();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
236
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
237 CheckInvariants();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
238 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
239
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
240
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
241 template <typename T, typename Payload>
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
242 void LeastRecentlyUsedIndex<T, Payload>::MakeMostRecent(T id, Payload updatedPayload)
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
243 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
244 if (!Contains(id))
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
245 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
246 throw OrthancException(ErrorCode_InexistentItem);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
247 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
248
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
249 typename Index::iterator it = index_.find(id);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
250 assert(it != index_.end());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
251
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
252 std::pair<T, Payload> item = *(it->second);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
253 item.second = updatedPayload;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
254
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
255 queue_.erase(it->second);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
256 queue_.push_front(item);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
257 index_[id] = queue_.begin();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
258
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
259 CheckInvariants();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
260 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
261
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
262
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
263 template <typename T, typename Payload>
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
264 Payload LeastRecentlyUsedIndex<T, Payload>::Invalidate(T id)
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
265 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
266 if (!Contains(id))
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
267 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
268 throw OrthancException(ErrorCode_InexistentItem);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
269 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
270
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
271 typename Index::iterator it = index_.find(id);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
272 assert(it != index_.end());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
273
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
274 Payload payload = it->second->second;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
275 queue_.erase(it->second);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
276 index_.erase(it);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
277
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
278 CheckInvariants();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
279 return payload;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
280 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
281
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
282
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
283 template <typename T, typename Payload>
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
284 T LeastRecentlyUsedIndex<T, Payload>::RemoveOldest(Payload& payload)
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
285 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
286 if (IsEmpty())
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
287 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
288 throw OrthancException(ErrorCode_BadSequenceOfCalls);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
289 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
290
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
291 std::pair<T, Payload> item = queue_.back();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
292 T oldest = item.first;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
293 payload = item.second;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
294
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
295 queue_.pop_back();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
296 assert(index_.find(oldest) != index_.end());
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
297 index_.erase(oldest);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
298
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
299 CheckInvariants();
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
300
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
301 return oldest;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
302 }
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
303
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
304
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
305 template <typename T, typename Payload>
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
306 T LeastRecentlyUsedIndex<T, Payload>::RemoveOldest()
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
307 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
308 if (IsEmpty())
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
309 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
310 throw OrthancException(ErrorCode_BadSequenceOfCalls);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
311 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
312
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
313 std::pair<T, Payload> item = queue_.back();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
314 T oldest = item.first;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
315
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
316 queue_.pop_back();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
317 assert(index_.find(oldest) != index_.end());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
318 index_.erase(oldest);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
319
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
320 CheckInvariants();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
321
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
322 return oldest;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
323 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
324
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
325
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
326 template <typename T, typename Payload>
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
327 const T& LeastRecentlyUsedIndex<T, Payload>::GetOldest() const
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
328 {
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
329 if (IsEmpty())
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
330 {
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
331 throw OrthancException(ErrorCode_BadSequenceOfCalls);
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
332 }
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
333
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
334 return queue_.back().first;
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
335 }
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
336
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
337
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
338 template <typename T, typename Payload>
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
339 const Payload& LeastRecentlyUsedIndex<T, Payload>::GetOldestPayload() const
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
340 {
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
341 if (IsEmpty())
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
342 {
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
343 throw OrthancException(ErrorCode_BadSequenceOfCalls);
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
344 }
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
345
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
346 return queue_.back().second;
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
347 }
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 }