| 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 | |
| 16 | |
| 17 | #ifndef Foundation_AccessExpirationDecorator_INCLUDED |
| 18 | #define Foundation_AccessExpirationDecorator_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Timestamp.h" |
| 22 | #include "Poco/Timespan.h" |
| 23 | |
| 24 | |
| 25 | namespace Poco { |
| 26 | |
| 27 | |
| 28 | template <typename TArgs> |
| 29 | class AccessExpirationDecorator |
| 30 | /// AccessExpirationDecorator adds an expiration method to values so that they can be used |
| 31 | /// with the UniqueAccessExpireCache |
| 32 | { |
| 33 | public: |
| 34 | AccessExpirationDecorator(): |
| 35 | _value(), |
| 36 | _span() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | AccessExpirationDecorator(const TArgs& p, const Poco::Timespan::TimeDiff& diffInMs): |
| 41 | /// Creates an element that will expire in diff milliseconds |
| 42 | _value(p), |
| 43 | _span(diffInMs*1000) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | AccessExpirationDecorator(const TArgs& p, const Poco::Timespan& timeSpan): |
| 48 | /// Creates an element that will expire after the given timeSpan |
| 49 | _value(p), |
| 50 | _span(timeSpan) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | |
| 55 | ~AccessExpirationDecorator() |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | const Poco::Timespan& getTimeout() const |
| 60 | { |
| 61 | return _span; |
| 62 | } |
| 63 | |
| 64 | const TArgs& value() const |
| 65 | { |
| 66 | return _value; |
| 67 | } |
| 68 | |
| 69 | TArgs& value() |
| 70 | { |
| 71 | return _value; |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | TArgs _value; |
| 76 | Timespan _span; |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | } // namespace Poco |
| 81 | |
| 82 | |
| 83 | #endif // Foundation_AccessExpirationDecorator_INCLUDED |
| 84 | |