1//
2// UniqueAccessExpireCache.h
3//
4// Library: Foundation
5// Package: Cache
6// Module: UniqueAccessExpireCache
7//
8// Definition of the UniqueAccessExpireCache 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_UniqueAccessExpireCache_INCLUDED
18#define Foundation_UniqueAccessExpireCache_INCLUDED
19
20
21#include "Poco/AbstractCache.h"
22#include "Poco/UniqueAccessExpireStrategy.h"
23
24
25namespace Poco {
26
27
28template <
29 class TKey,
30 class TValue,
31 class TMutex = FastMutex,
32 class TEventMutex = FastMutex
33>
34class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
35 /// An UniqueAccessExpireCache caches entries for a given time span. 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::Timespan& getTimeout() const;
41 ///
42 /// which returns the relative timespan for how long the entry should be valid without being accessed!
43 /// The absolute expire timepoint is calculated as now() + getTimeout().
44 /// Accessing an object will update this absolute expire timepoint.
45 /// You can use the Poco::AccessExpirationDecorator to add the getExpiration
46 /// method to values that do not have a getExpiration function.
47 ///
48 /// Be careful when using an UniqueAccessExpireCache. A cache is often used
49 /// like cache.has(x) followed by cache.get x). Note that it could happen
50 /// that the "has" call works, then the current execution thread gets descheduled, time passes,
51 /// the entry gets invalid, thus leading to an empty SharedPtr being returned
52 /// when "get" is invoked.
53{
54public:
55 UniqueAccessExpireCache():
56 AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(UniqueAccessExpireStrategy<TKey, TValue>())
57 {
58 }
59
60 ~UniqueAccessExpireCache()
61 {
62 }
63
64private:
65 UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
66 UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
67};
68
69
70} // namespace Poco
71
72
73#endif // Foundation_UniqueAccessExpireCache_INCLUDED
74