UniqueExpireCache.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // UniqueExpireCache.h
  3. //
  4. // Library: Foundation
  5. // Package: Cache
  6. // Module: UniqueExpireCache
  7. //
  8. // Definition of the UniqueExpireCache 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_UniqueExpireCache_INCLUDED
  16. #define Foundation_UniqueExpireCache_INCLUDED
  17. #include "Poco/AbstractCache.h"
  18. #include "Poco/UniqueExpireStrategy.h"
  19. namespace Poco {
  20. template <
  21. class TKey,
  22. class TValue,
  23. class TMutex = FastMutex,
  24. class TEventMutex = FastMutex
  25. >
  26. class UniqueExpireCache: public AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
  27. /// An UniqueExpireCache caches entries for a given time amount. In contrast
  28. /// to ExpireCache which only allows to set a per cache expiration value, it allows to define
  29. /// expiration per CacheEntry.
  30. /// Each TValue object must thus offer the following method:
  31. ///
  32. /// const Poco::Timestamp& getExpiration() const;
  33. ///
  34. /// which returns the absolute timepoint when the entry will be invalidated.
  35. /// Accessing an object will NOT update this absolute expire timepoint.
  36. /// You can use the Poco::ExpirationDecorator to add the getExpiration
  37. /// method to values that do not have a getExpiration function.
  38. ///
  39. /// Be careful when using an UniqueExpireCache. A cache is often used
  40. /// like cache.has(x) followed by cache.get x). Note that it could happen
  41. /// that the "has" call works, then the current execution thread gets descheduled, time passes,
  42. /// the entry gets invalid, thus leading to an empty SharedPtr being returned
  43. /// when "get" is invoked.
  44. {
  45. public:
  46. UniqueExpireCache():
  47. AbstractCache<TKey, TValue, UniqueExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(UniqueExpireStrategy<TKey, TValue>())
  48. {
  49. }
  50. ~UniqueExpireCache()
  51. {
  52. }
  53. private:
  54. UniqueExpireCache(const UniqueExpireCache& aCache);
  55. UniqueExpireCache& operator = (const UniqueExpireCache& aCache);
  56. };
  57. } // namespace Poco
  58. #endif // Foundation_UniqueExpireCache_INCLUDED