Parent

Merb::Cache::SHA1Store

Strategy store that uses SHA1 hex of base cache key and parameters as cache key.

It is good for caching of expensive search queries that use multiple parameters passed via query string of request.

Public Class Methods

new(config = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 13
def initialize(config = {})
  super(config)
  @map = {}
end

Public Instance Methods

delete(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 50
def delete(key, parameters = {})
  @stores.map {|c| c.delete(digest(key, parameters))}.any?
end
delete_all!() click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 54
def delete_all!
  @stores.map {|c| c.delete_all! }.all?
end
digest(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 58
def digest(key, parameters = {})
  @map[[key, parameters]] ||= Digest::SHA1.hexdigest("#{key}#{parameters.to_sha2}")
end
exists?(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 46
def exists?(key, parameters = {})
  @stores.capture_first {|c| c.exists?(digest(key, parameters))}
end
fetch(key, parameters = {}, conditions = {}, &blk) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 42
def fetch(key, parameters = {}, conditions = {}, &blk)
  read(key, parameters) || (writable?(key, parameters, conditions) && @stores.capture_first {|c| c.fetch(digest(key, parameters), {}, conditions, &blk)})
end
read(key, parameters = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 26
def read(key, parameters = {})
  @stores.capture_first {|c| c.read(digest(key, parameters))}
end
writable?(key, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 18
def writable?(key, parameters = {}, conditions = {})
  case key
  when String, Numeric, Symbol
    @stores.any? {|c| c.writable?(digest(key, parameters), {}, conditions)}
  else nil
  end
end
write(key, data = nil, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 30
def write(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    @stores.capture_first {|c| c.write(digest(key, parameters), data, {}, conditions)}
  end
end
write_all(key, data = nil, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/sha1_store.rb, line 36
def write_all(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    @stores.map {|c| c.write_all(digest(key, parameters), data, {}, conditions)}.all?
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.