Class: Cachetastic::Adapters::StoreObject

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/store_object.rb

Overview

:nodoc:#

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject

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

#keyObject

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

#valueObject

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

Returns:

  • (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

#sizeObject



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