| 1 | // |
| 2 | // ExpireCache.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Cache |
| 6 | // Module: ExpireCache |
| 7 | // |
| 8 | // Definition of the ExpireCache 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_ExpireCache_INCLUDED |
| 18 | #define Foundation_ExpireCache_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/AbstractCache.h" |
| 22 | #include "Poco/ExpireStrategy.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 ExpireCache: public AbstractCache<TKey, TValue, ExpireStrategy<TKey, TValue>, TMutex, TEventMutex> |
| 35 | /// An ExpireCache caches entries for a fixed time period (per default 10 minutes). |
| 36 | /// Entries expire independently of the access pattern, i.e. after a constant time. |
| 37 | /// If you require your objects to expire after they were not accessed for a given time |
| 38 | /// period use a Poco::AccessExpireCache. |
| 39 | /// |
| 40 | /// Be careful when using an ExpireCache. A cache is often used |
| 41 | /// like cache.has(x) followed by cache.get x). Note that it could happen |
| 42 | /// that the "has" call works, then the current execution thread gets descheduled, time passes, |
| 43 | /// the entry gets invalid, thus leading to an empty SharedPtr being returned |
| 44 | /// when "get" is invoked. |
| 45 | { |
| 46 | public: |
| 47 | ExpireCache(Timestamp::TimeDiff expire = 600000): |
| 48 | AbstractCache<TKey, TValue, ExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(ExpireStrategy<TKey, TValue>(expire)) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | ~ExpireCache() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | ExpireCache(const ExpireCache& aCache); |
| 58 | ExpireCache& operator = (const ExpireCache& aCache); |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | } // namespace Poco |
| 63 | |
| 64 | |
| 65 | #endif // Foundation_ExpireCache_INCLUDED |
| 66 | |