1 | // |
2 | // AccessExpireCache.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Cache |
6 | // Module: AccessExpireCache |
7 | // |
8 | // Definition of the AccessExpireCache 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_AccessExpireCache_INCLUDED |
18 | #define Foundation_AccessExpireCache_INCLUDED |
19 | |
20 | |
21 | #include "Poco/AbstractCache.h" |
22 | #include "Poco/AccessExpireStrategy.h" |
23 | |
24 | |
25 | namespace Poco { |
26 | |
27 | |
28 | template < |
29 | class TKey, |
30 | class TValue, |
31 | class TMutex = FastMutex, |
32 | class TEventMutex = FastMutex |
33 | > |
34 | class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex> |
35 | /// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes). |
36 | /// Entries expire when they are not accessed with get() during this time period. Each access resets |
37 | /// the start time for expiration. |
38 | /// Be careful when using an AccessExpireCache. A cache is often used |
39 | /// like cache.has(x) followed by cache.get x). Note that it could happen |
40 | /// that the "has" call works, then the current execution thread gets descheduled, time passes, |
41 | /// the entry gets invalid, thus leading to an empty SharedPtr being returned |
42 | /// when "get" is invoked. |
43 | { |
44 | public: |
45 | AccessExpireCache(Timestamp::TimeDiff expire = 600000): |
46 | AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(AccessExpireStrategy<TKey, TValue>(expire)) |
47 | { |
48 | } |
49 | |
50 | ~AccessExpireCache() |
51 | { |
52 | } |
53 | |
54 | private: |
55 | AccessExpireCache(const AccessExpireCache& aCache); |
56 | AccessExpireCache& operator = (const AccessExpireCache& aCache); |
57 | }; |
58 | |
59 | |
60 | } // namespace Poco |
61 | |
62 | |
63 | #endif // Foundation_AccessExpireCache_INCLUDED |
64 | |