Class: Cachetastic::Adapters::StoreObject
- Defined in:
- lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb
Overview
:nodoc:#
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key, value, expiry) ⇒ StoreObject
constructor
A new instance of StoreObject.
- #invalid? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(key, value, expiry) ⇒ StoreObject
Returns a new instance of StoreObject.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 6 def initialize(key, value, expiry) self.key = key self.value = value begin self.expires_at = (Time.now + (expiry == 0 ? (31536000) : expiry)) # 31536000 = one year rescue RangeError => e self.expires_at = Time.at(expiry) end # puts "now: #{Time.now}" # puts "expiry: #{expiry}" # puts "expires_at: #{self.expires_at}" end |
Instance Attribute Details
#expires_at ⇒ Object
Returns the value of attribute expires_at.
4 5 6 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 4 def expires_at @expires_at end |
#key ⇒ Object
Returns the value of attribute key.
2 3 4 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 2 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 3 def value @value end |
Instance Method Details
#invalid? ⇒ Boolean
24 25 26 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 24 def invalid? Time.now >= self.expires_at end |
#size ⇒ Object
19 20 21 22 |
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb', line 19 def size return self.value.size if self.value.respond_to?(:size) -1 end |