Class: Cash::Mock::CacheEntry
- Inherits:
-
Object
- Object
- Cash::Mock::CacheEntry
- Defined in:
- lib/cash/mock.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #decrement(amount = 1) ⇒ Object
- #expired? ⇒ Boolean
- #increment(amount = 1) ⇒ Object
-
#initialize(value, raw, ttl) ⇒ CacheEntry
constructor
A new instance of CacheEntry.
- #to_i ⇒ Object
- #unmarshal ⇒ Object
Constructor Details
#initialize(value, raw, ttl) ⇒ CacheEntry
Returns a new instance of CacheEntry.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cash/mock.rb', line 16 def initialize(value, raw, ttl) if raw @value = value.to_s else @value = Marshal.dump(value) end if ttl.zero? @ttl = self.class.default_ttl else @ttl = ttl end @expires_at = self.class.now + @ttl end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/cash/mock.rb', line 6 def value @value end |
Class Method Details
.default_ttl ⇒ Object
8 9 10 |
# File 'lib/cash/mock.rb', line 8 def self.default_ttl 1_000_000 end |
.now ⇒ Object
12 13 14 |
# File 'lib/cash/mock.rb', line 12 def self.now Time.now end |
Instance Method Details
#decrement(amount = 1) ⇒ Object
41 42 43 |
# File 'lib/cash/mock.rb', line 41 def decrement(amount = 1) @value = (@value.to_i - amount).to_s end |
#expired? ⇒ Boolean
33 34 35 |
# File 'lib/cash/mock.rb', line 33 def expired? self.class.now > @expires_at end |
#increment(amount = 1) ⇒ Object
37 38 39 |
# File 'lib/cash/mock.rb', line 37 def increment(amount = 1) @value = (@value.to_i + amount).to_s end |
#to_i ⇒ Object
49 50 51 |
# File 'lib/cash/mock.rb', line 49 def to_i @value.to_i end |
#unmarshal ⇒ Object
45 46 47 |
# File 'lib/cash/mock.rb', line 45 def unmarshal Marshal.load(@value) end |