Class: MiniCache::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_cache/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, expires_in: nil) ⇒ Data

Returns a new instance of Data.



8
9
10
11
# File 'lib/mini_cache/data.rb', line 8

def initialize(value, expires_in: nil)
  @value = value
  @expires_in = expires_in.nil? ? nil : Time.now + expires_in
end

Instance Attribute Details

#expires_inObject (readonly)

Returns the value of attribute expires_in.



6
7
8
# File 'lib/mini_cache/data.rb', line 6

def expires_in
  @expires_in
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/mini_cache/data.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/mini_cache/data.rb', line 17

def ==(other)
  other.is_a?(MiniCache::Data) && @value == other.value
end

#expired?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mini_cache/data.rb', line 13

def expired?
  !@expires_in.nil? && Time.now > @expires_in
end