1//
2// AccessExpireStrategy.h
3//
4// Library: Foundation
5// Package: Cache
6// Module: AccessExpireStrategy
7//
8// Definition of the AccessExpireStrategy 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_AccessExpireStrategy_INCLUDED
18#define Foundation_AccessExpireStrategy_INCLUDED
19
20
21#include "Poco/KeyValueArgs.h"
22#include "Poco/ValidArgs.h"
23#include "Poco/ExpireStrategy.h"
24#include "Poco/Bugcheck.h"
25#include "Poco/Timestamp.h"
26#include "Poco/EventArgs.h"
27#include <set>
28#include <map>
29
30
31namespace Poco {
32
33
34template <
35 class TKey,
36 class TValue
37>
38class AccessExpireStrategy: public ExpireStrategy<TKey, TValue>
39 /// An AccessExpireStrategy implements time and access based expiration of cache entries
40{
41public:
42 AccessExpireStrategy(Timestamp::TimeDiff expireTimeInMilliSec): ExpireStrategy<TKey, TValue>(expireTimeInMilliSec)
43 /// Create an expire strategy. Note that the smallest allowed caching time is 25ms.
44 /// Anything lower than that is not useful with current operating systems.
45 {
46 }
47
48 ~AccessExpireStrategy()
49 {
50 }
51
52 void onGet(const void*, const TKey& key)
53 {
54 // get triggers an update to the expiration time
55 typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key);
56 if (it != this->_keys.end())
57 {
58 this->_keyIndex.erase(it->second);
59 Timestamp now;
60 typename ExpireStrategy<TKey, TValue>::IndexIterator itIdx =
61 this->_keyIndex.insert(typename ExpireStrategy<TKey, TValue>::TimeIndex::value_type(now, key));
62 it->second = itIdx;
63 }
64 }
65};
66
67
68} // namespace Poco
69
70
71#endif // Foundation_AccessExpireStrategy_INCLUDED
72