Adds expiration support to the underlying store
`store`, `load` and `key?` support the `:expires` option to set/update the expiration time.
@api public
@param [Moneta store] adapter The underlying store @param [Hash] options @option options [String] :expires Default expiration time
# File lib/moneta/expires.rb, line 14 def initialize(adapter, options = {}) raise 'Store already supports feature :expires' if adapter.supports?(:expires) super self.default_expires = options[:expires] end
(see Proxy#store)
# File lib/moneta/expires.rb, line 51 def create(key, value, options = {}) return super if options.include?(:raw) expires = expires_at(options) @adapter.create(key, new_entry(value, expires), Utils.without(options, :expires)) end
(see Proxy#delete)
# File lib/moneta/expires.rb, line 44 def delete(key, options = {}) return super if options.include?(:raw) value, expires = super value if !expires || Time.now.to_i <= expires end
(see Proxy#key?)
# File lib/moneta/expires.rb, line 21 def key?(key, options = {}) # Transformer might raise exception load_entry(key, options) != nil rescue Exception super(key, Utils.without(options, :expires)) end
(see Proxy#load)
# File lib/moneta/expires.rb, line 29 def load(key, options = {}) return super if options.include?(:raw) value, expires = load_entry(key, options) value end
(see Proxy#store)
# File lib/moneta/expires.rb, line 36 def store(key, value, options = {}) return super if options.include?(:raw) expires = expires_at(options) super(key, new_entry(value, expires), Utils.without(options, :expires)) value end
Generated with the Darkfish Rdoc Generator 2.