UniqueAccessExpireLRUCache.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // UniqueAccessExpireLRUCache.h
  3. //
  4. // Library: Foundation
  5. // Package: Cache
  6. // Module: UniqueAccessExpireLRUCache
  7. //
  8. // Definition of the UniqueAccessExpireLRUCache 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_UniqueAccessExpireLRUCache_INCLUDED
  16. #define Foundation_UniqueAccessExpireLRUCache_INCLUDED
  17. #include "Poco/AbstractCache.h"
  18. #include "Poco/StrategyCollection.h"
  19. #include "Poco/UniqueAccessExpireStrategy.h"
  20. #include "Poco/LRUStrategy.h"
  21. namespace Poco {
  22. template <
  23. class TKey,
  24. class TValue,
  25. class TMutex = FastMutex,
  26. class TEventMutex = FastMutex
  27. >
  28. class UniqueAccessExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>
  29. /// A UniqueAccessExpireLRUCache combines LRU caching and time based per entry expire caching.
  30. /// One can define for each cache entry a seperate timepoint
  31. /// but also limit the size of the cache (per default: 1024).
  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. public:
  43. UniqueAccessExpireLRUCache(long cacheSize = 1024):
  44. AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>(StrategyCollection<TKey, TValue>())
  45. {
  46. this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
  47. this->_strategy.pushBack(new UniqueAccessExpireStrategy<TKey, TValue>());
  48. }
  49. ~UniqueAccessExpireLRUCache()
  50. {
  51. }
  52. private:
  53. UniqueAccessExpireLRUCache(const UniqueAccessExpireLRUCache& aCache);
  54. UniqueAccessExpireLRUCache& operator = (const UniqueAccessExpireLRUCache& aCache);
  55. };
  56. } // namespace Poco
  57. #endif // Foundation_UniqueAccessExpireLRUCache_INCLUDED