UniqueAccessExpireCache.h 2.3 KB

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