1 | // |
2 | // UniqueExpireLRUCache.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Cache |
6 | // Module: UniqueExpireLRUCache |
7 | // |
8 | // Definition of the UniqueExpireLRUCache class. |
9 | // |
10 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_UniqueExpireLRUCache_INCLUDED |
18 | #define Foundation_UniqueExpireLRUCache_INCLUDED |
19 | |
20 | |
21 | #include "Poco/AbstractCache.h" |
22 | #include "Poco/StrategyCollection.h" |
23 | #include "Poco/UniqueExpireStrategy.h" |
24 | #include "Poco/LRUStrategy.h" |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | template < |
31 | class TKey, |
32 | class TValue, |
33 | class TMutex = FastMutex, |
34 | class TEventMutex = FastMutex |
35 | > |
36 | class UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex> |
37 | /// A UniqueExpireLRUCache combines LRU caching and time based per entry expire caching. |
38 | /// One can define for each cache entry a separate timepoint |
39 | /// but also limit the size of the cache (per default: 1024). |
40 | /// Each TValue object must thus offer the following method: |
41 | /// |
42 | /// const Poco::Timestamp& getExpiration() const; |
43 | /// |
44 | /// which returns the absolute timepoint when the entry will be invalidated. |
45 | /// Accessing an object will NOT update this absolute expire timepoint. |
46 | /// You can use the Poco::ExpirationDecorator to add the getExpiration |
47 | /// method to values that do not have a getExpiration function. |
48 | { |
49 | public: |
50 | UniqueExpireLRUCache(std::size_t cacheSize = 1024): |
51 | AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>(StrategyCollection<TKey, TValue>()) |
52 | { |
53 | this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize)); |
54 | this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>()); |
55 | } |
56 | |
57 | ~UniqueExpireLRUCache() |
58 | { |
59 | } |
60 | |
61 | private: |
62 | UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache); |
63 | UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache); |
64 | }; |
65 | |
66 | |
67 | } // namespace Poco |
68 | |
69 | |
70 | #endif // Foundation_UniqueExpireLRUCache_INCLUDED |
71 | |