AccessExpireCache.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // AccessExpireCache.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/AccessExpireCache.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Cache
  8. // Module: AccessExpireCache
  9. //
  10. // Definition of the AccessExpireCache class.
  11. //
  12. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_AccessExpireCache_INCLUDED
  18. #define Foundation_AccessExpireCache_INCLUDED
  19. #include "Poco/AbstractCache.h"
  20. #include "Poco/AccessExpireStrategy.h"
  21. namespace Poco {
  22. template <
  23. class TKey,
  24. class TValue,
  25. class TMutex = FastMutex,
  26. class TEventMutex = FastMutex
  27. >
  28. class AccessExpireCache: public AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
  29. /// An AccessExpireCache caches entries for a fixed time period (per default 10 minutes).
  30. /// Entries expire when they are not accessed with get() during this time period. Each access resets
  31. /// the start time for expiration.
  32. /// Be careful when using an AccessExpireCache. A cache is often used
  33. /// like cache.has(x) followed by cache.get x). Note that it could happen
  34. /// that the "has" call works, then the current execution thread gets descheduled, time passes,
  35. /// the entry gets invalid, thus leading to an empty SharedPtr being returned
  36. /// when "get" is invoked.
  37. {
  38. public:
  39. AccessExpireCache(Timestamp::TimeDiff expire = 600000):
  40. AbstractCache<TKey, TValue, AccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(AccessExpireStrategy<TKey, TValue>(expire))
  41. {
  42. }
  43. ~AccessExpireCache()
  44. {
  45. }
  46. private:
  47. AccessExpireCache(const AccessExpireCache& aCache);
  48. AccessExpireCache& operator = (const AccessExpireCache& aCache);
  49. };
  50. } // namespace Poco
  51. #endif // Foundation_AccessExpireCache_INCLUDED