UniqueExpireLRUCache.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // UniqueExpireLRUCache.h
  3. //
  4. // Library: Foundation
  5. // Package: Cache
  6. // Module: UniqueExpireLRUCache
  7. //
  8. // Definition of the UniqueExpireLRUCache 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_UniqueExpireLRUCache_INCLUDED
  16. #define Foundation_UniqueExpireLRUCache_INCLUDED
  17. #include "Poco/AbstractCache.h"
  18. #include "Poco/StrategyCollection.h"
  19. #include "Poco/UniqueExpireStrategy.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 UniqueExpireLRUCache: public AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>
  29. /// A UniqueExpireLRUCache 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::Timestamp& getExpiration() const;
  35. ///
  36. /// which returns the absolute timepoint when the entry will be invalidated.
  37. /// Accessing an object will NOT update this absolute expire timepoint.
  38. /// You can use the Poco::ExpirationDecorator to add the getExpiration
  39. /// method to values that do not have a getExpiration function.
  40. {
  41. public:
  42. UniqueExpireLRUCache(long cacheSize = 1024):
  43. AbstractCache<TKey, TValue, StrategyCollection<TKey, TValue>, TMutex, TEventMutex>(StrategyCollection<TKey, TValue>())
  44. {
  45. this->_strategy.pushBack(new LRUStrategy<TKey, TValue>(cacheSize));
  46. this->_strategy.pushBack(new UniqueExpireStrategy<TKey, TValue>());
  47. }
  48. ~UniqueExpireLRUCache()
  49. {
  50. }
  51. private:
  52. UniqueExpireLRUCache(const UniqueExpireLRUCache& aCache);
  53. UniqueExpireLRUCache& operator = (const UniqueExpireLRUCache& aCache);
  54. };
  55. } // namespace Poco
  56. #endif // Foundation_UniqueExpireLRUCache_INCLUDED