Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

Moneta::Expires

Adds expiration support to the underlying store

`store`, `load` and `key?` support the `:expires` option to set/update the expiration time.

@api public

Public Class Methods

new(adapter, options = {}) click to toggle source

@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

Public Instance Methods

create(key, value, options = {}) click to toggle source

(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
delete(key, options = {}) click to toggle source

(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
key?(key, options = {}) click to toggle source

(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
load(key, options = {}) click to toggle source

(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
store(key, value, options = {}) click to toggle source

(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

[Validate]

Generated with the Darkfish Rdoc Generator 2.