ExpireCache.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // ExpireCache.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/ExpireCache.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Cache
  8. // Module: ExpireCache
  9. //
  10. // Definition of the ExpireCache 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_ExpireCache_INCLUDED
  18. #define Foundation_ExpireCache_INCLUDED
  19. #include "Poco/AbstractCache.h"
  20. #include "Poco/ExpireStrategy.h"
  21. namespace Poco {
  22. template <
  23. class TKey,
  24. class TValue,
  25. class TMutex = FastMutex,
  26. class TEventMutex = FastMutex
  27. >
  28. class ExpireCache: public AbstractCache<TKey, TValue, ExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
  29. /// An ExpireCache caches entries for a fixed time period (per default 10 minutes).
  30. /// Entries expire independently of the access pattern, i.e. after a constant time.
  31. /// If you require your objects to expire after they were not accessed for a given time
  32. /// period use a Poco::AccessExpireCache.
  33. ///
  34. /// Be careful when using an ExpireCache. A cache is often used
  35. /// like cache.has(x) followed by cache.get x). Note that it could happen
  36. /// that the "has" call works, then the current execution thread gets descheduled, time passes,
  37. /// the entry gets invalid, thus leading to an empty SharedPtr being returned
  38. /// when "get" is invoked.
  39. {
  40. public:
  41. ExpireCache(Timestamp::TimeDiff expire = 600000):
  42. AbstractCache<TKey, TValue, ExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(ExpireStrategy<TKey, TValue>(expire))
  43. {
  44. }
  45. ~ExpireCache()
  46. {
  47. }
  48. private:
  49. ExpireCache(const ExpireCache& aCache);
  50. ExpireCache& operator = (const ExpireCache& aCache);
  51. };
  52. } // namespace Poco
  53. #endif // Foundation_ExpireCache_INCLUDED