1//
2// UniqueExpireCache.h
3//
4// Library: Foundation
5// Package: Cache
6// Module: UniqueExpireCache
7//
8// Definition of the UniqueExpireCache 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_UniqueExpireCache_INCLUDED
18#define Foundation_UniqueExpireCache_INCLUDED
19
20
21#include "Poco/AbstractCache.h"
22#include "Poco/UniqueExpireStrategy.h"
23
24
25namespace Poco {
26
27
28template <
29 class TKey,
30 class TValue,
31 class TMutex = FastMutex,
32 class TEventMutex = FastMutex
33>
34class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
35 /// An UniqueExpireCache caches entries for a given time amount. In contrast
36 /// to ExpireCache which only allows to set a per cache expiration value, it allows to define
37 /// expiration per CacheEntry.
38 /// Each TValue object must thus offer the following method:
39 ///
40 /// const Poco::Timestamp& getExpiration() const;
41 ///
42 /// which returns the absolute timepoint when the entry will be invalidated.
43 /// Accessing an object will NOT update this absolute expire timepoint.
44 /// You can use the Poco::ExpirationDecorator to add the getExpiration
45 /// method to values that do not have a getExpiration function.
46 ///
47 /// Be careful when using an UniqueExpireCache. A cache is often used
48 /// like cache.has(x) followed by cache.get x). Note that it could happen
49 /// that the "has" call works, then the current execution thread gets descheduled, time passes,
50 /// the entry gets invalid, thus leading to an empty SharedPtr being returned
51 /// when "get" is invoked.
52{
53public:
54 UniqueExpireCache():
55 AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(UniqueExpireStrategy<TKey, TValue>())
56 {
57 }
58
59 ~UniqueExpireCache()
60 {
61 }
62
63private:
64 UniqueExpireCache(const UniqueExpireCache& aCache);
65 UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
66};
67
68
69} // namespace Poco
70
71
72#endif // Foundation_UniqueExpireCache_INCLUDED
73