Class: Juno::Expires
Overview
Adds expiration support to the underlying store
#store and #load support the :expires option to set/update the expiration time.
Instance Attribute Summary
Attributes inherited from Proxy
#adapter
Instance Method Summary
collapse
Methods inherited from Proxy
#clear, #close, #initialize
Methods inherited from Base
#[], #[]=, #close, #fetch
Constructor Details
This class inherits a constructor from Juno::Proxy
Instance Method Details
#delete(key, options = {}) ⇒ Object
31
32
33
|
# File 'lib/juno/expires.rb', line 31
def delete(key, options = {})
check_expired(key, super, false)
end
|
#key?(key, options = {}) ⇒ Boolean
9
10
11
|
# File 'lib/juno/expires.rb', line 9
def key?(key, options = {})
!!load(key, options)
end
|
#load(key, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/juno/expires.rb', line 13
def load(key, options = {})
value = check_expired(key, super(key, options))
if value && options.include?(:expires)
store(key, value, options)
else
value
end
end
|
#store(key, value, options = {}) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/juno/expires.rb', line 22
def store(key, value, options = {})
if expires = options.delete(:expires)
super(key, [value, Time.now.to_i + expires].compact, options)
else
super(key, [value], options)
end
value
end
|