UniqueAccessExpireCache.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // UniqueAccessExpireCache.h
  3. //
  4. // Library: Foundation
  5. // Package: Cache
  6. // Module: UniqueAccessExpireCache
  7. //
  8. // Definition of the UniqueAccessExpireCache 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_UniqueAccessExpireCache_INCLUDED
  16. #define Foundation_UniqueAccessExpireCache_INCLUDED
  17. #include "Poco/AbstractCache.h"
  18. #include "Poco/UniqueAccessExpireStrategy.h"
  19. namespace Poco {
  20. template <
  21. class TKey,
  22. class TValue,
  23. class TMutex = FastMutex,
  24. class TEventMutex = FastMutex
  25. >
  26. class UniqueAccessExpireCache: public AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>
  27. /// An UniqueAccessExpireCache caches entries for a given time span. 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::Timespan& getTimeout() const;
  33. ///
  34. /// which returns the relative timespan for how long the entry should be valid without being accessed!
  35. /// The absolute expire timepoint is calculated as now() + getTimeout().
  36. /// Accessing an object will update this absolute expire timepoint.
  37. /// You can use the Poco::AccessExpirationDecorator to add the getExpiration
  38. /// method to values that do not have a getExpiration function.
  39. ///
  40. /// Be careful when using an UniqueAccessExpireCache. A cache is often used
  41. /// like cache.has(x) followed by cache.get x). Note that it could happen
  42. /// that the "has" call works, then the current execution thread gets descheduled, time passes,
  43. /// the entry gets invalid, thus leading to an empty SharedPtr being returned
  44. /// when "get" is invoked.
  45. {
  46. public:
  47. UniqueAccessExpireCache():
  48. AbstractCache<TKey, TValue, UniqueAccessExpireStrategy<TKey, TValue>, TMutex, TEventMutex>(UniqueAccessExpireStrategy<TKey, TValue>())
  49. {
  50. }
  51. ~UniqueAccessExpireCache()
  52. {
  53. }
  54. private:
  55. UniqueAccessExpireCache(const UniqueAccessExpireCache& aCache);
  56. UniqueAccessExpireCache& operator = (const UniqueAccessExpireCache& aCache);
  57. };
  58. } // namespace Poco
  59. #endif // Foundation_UniqueAccessExpireCache_INCLUDED