1 | // |
2 | // UniqueAccessExpireLRUCache.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Cache |
6 | // Module: UniqueAccessExpireLRUCache |
7 | // |
8 | // Definition of the UniqueAccessExpireLRUCache 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_UniqueAccessExpireLRUCache_INCLUDED |
18 | #define Foundation_UniqueAccessExpireLRUCache_INCLUDED |
19 | |
20 | |
21 | #include "Poco/AbstractCache.h" |
22 | #include "Poco/StrategyCollection.h" |
23 | #include "Poco/UniqueAccessExpireStrategy.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 UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex> |
37 | /// A UniqueAccessExpireLRUCache 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::Timespan& getTimeout() const; |
43 | /// |
44 | /// which returns the relative timespan for how long the entry should be valid without being accessed! |
45 | /// The absolute expire timepoint is calculated as now() + getTimeout(). |
46 | /// Accessing an object will update this absolute expire timepoint. |
47 | /// You can use the Poco::AccessExpirationDecorator to add the getExpiration |
48 | /// method to values that do not have a getExpiration function. |
49 | { |
50 | public: |
51 | UniqueAccessExpireLRUCache(long cacheSize = 1024): |
52 | AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>(StrategyCollection<TKey, TValue>()) |
53 | { |
54 | this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize)); |
55 | this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>()); |
56 | } |
57 | |
58 | ~UniqueAccessExpireLRUCache() |
59 | { |
60 | } |
61 | |
62 | private: |
63 | UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache); |
64 | UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache); |
65 | }; |
66 | |
67 | |
68 | } // namespace Poco |
69 | |
70 | |
71 | #endif // Foundation_UniqueAccessExpireLRUCache_INCLUDED |
72 | |