AccessExpirationDecorator.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // AccessExpirationDecorator.h
  3. //
  4. // Library: Foundation
  5. // Package: Cache
  6. // Module: AccessExpirationDecorator
  7. //
  8. // Implementation of the AccessExpirationDecorator template.
  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_AccessExpirationDecorator_INCLUDED
  16. #define Foundation_AccessExpirationDecorator_INCLUDED
  17. #include "Poco/Timestamp.h"
  18. #include "Poco/Timespan.h"
  19. namespace Poco {
  20. template <typename TArgs>
  21. class AccessExpirationDecorator
  22. /// AccessExpirationDecorator adds an expiration method to values so that they can be used
  23. /// with the UniqueAccessExpireCache
  24. {
  25. public:
  26. AccessExpirationDecorator():
  27. _value(),
  28. _span()
  29. {
  30. }
  31. AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs):
  32. /// Creates an element that will expire in diff milliseconds
  33. _value(p),
  34. _span(diffInMs*1000)
  35. {
  36. }
  37. AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan):
  38. /// Creates an element that will expire after the given timeSpan
  39. _value(p),
  40. _span(timeSpan)
  41. {
  42. }
  43. ~AccessExpirationDecorator()
  44. {
  45. }
  46. const Poco::Timespan& getTimeout() const
  47. {
  48. return _span;
  49. }
  50. const TArgs& value() const
  51. {
  52. return _value;
  53. }
  54. TArgs& value()
  55. {
  56. return _value;
  57. }
  58. private:
  59. TArgs _value;
  60. Timespan _span;
  61. };
  62. } // namespace Poco
  63. #endif // Foundation_AccessExpirationDecorator_INCLUDED