Class: LowCardTables::LowCardTable::CacheExpiration::FixedCacheExpirationPolicy
- Inherits:
-
Object
- Object
- LowCardTables::LowCardTable::CacheExpiration::FixedCacheExpirationPolicy
- Defined in:
- lib/low_card_tables/low_card_table/cache_expiration/fixed_cache_expiration_policy.rb
Overview
A FixedCacheExpirationPolicy is a very simple kind of cache-expiration policy: the cache expires a certain amount of time after it is filled, every time.
Instance Attribute Summary collapse
-
#expiration_time ⇒ Object
readonly
Returns the value of attribute expiration_time.
Instance Method Summary collapse
-
#initialize(expiration_time) ⇒ FixedCacheExpirationPolicy
constructor
A new instance of FixedCacheExpirationPolicy.
- #stale?(cache_time, current_time) ⇒ Boolean
Constructor Details
#initialize(expiration_time) ⇒ FixedCacheExpirationPolicy
Returns a new instance of FixedCacheExpirationPolicy.
7 8 9 10 11 12 13 |
# File 'lib/low_card_tables/low_card_table/cache_expiration/fixed_cache_expiration_policy.rb', line 7 def initialize(expiration_time) unless expiration_time && expiration_time.kind_of?(Numeric) && expiration_time >= 0.0 raise ArgumentError, "Expiration time must be a nonnegative number, not: #{expiration_time.inspect}" end @expiration_time = expiration_time end |
Instance Attribute Details
#expiration_time ⇒ Object (readonly)
Returns the value of attribute expiration_time.
19 20 21 |
# File 'lib/low_card_tables/low_card_table/cache_expiration/fixed_cache_expiration_policy.rb', line 19 def expiration_time @expiration_time end |
Instance Method Details
#stale?(cache_time, current_time) ⇒ Boolean
15 16 17 |
# File 'lib/low_card_tables/low_card_table/cache_expiration/fixed_cache_expiration_policy.rb', line 15 def stale?(cache_time, current_time) (current_time - cache_time) >= @expiration_time end |