AccessExpireCache.h 1.7 KB

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