Parent

Merb::Cache::AdhocStore

General purpose store, use for your own contexts. Since it wraps access to multiple fundamental stores, it’s easy to use this strategy store with distributed cache stores like Memcached.

Attributes

stores[RW]

Public Class Methods

new(*names) click to toggle source
# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 14
def initialize(*names)
  @stores = names.map {|n| Merb::Cache[n]}
end

Public Instance Methods

delete(key, parameters = {}) click to toggle source

deletes the entry for the key & parameter from the store.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 58
def delete(key, parameters = {})
  @stores.map {|s| s.delete(key, parameters)}.any?
end
delete_all!() click to toggle source

deletes all entries for the key & parameters for the store. considered dangerous because strategy stores which call delete_all! on their context stores could delete other store’s entrees.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 65
def delete_all!
  @stores.map {|s| s.delete_all!}.all?
end
exists?(key, parameters = {}) click to toggle source

returns true/false/nil based on if data identified by the key & parameters is persisted in the store.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 53
def exists?(key, parameters = {})
  @stores.capture_first {|s| s.exists?(key, parameters)}
end
fetch(key, parameters = {}, conditions = {}, &blk) click to toggle source

tries to read the data from the store. If that fails, it calls the block parameter and persists the result. If it cannot be fetched, the block call is returned.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 45
def fetch(key, parameters = {}, conditions = {}, &blk)
  read(key, parameters) ||
    @stores.capture_first {|s| s.fetch(key, parameters, conditions, &blk)} ||
    blk.call
end
read(key, parameters = {}) click to toggle source

gets the data from the store identified by the key & parameters. return nil if the entry does not exist.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 24
def read(key, parameters = {})
  @stores.capture_first {|s| s.read(key, parameters)}
end
writable?(key, parameters = {}, conditions = {}) click to toggle source
# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 18
def writable?(key, parameters = {}, conditions = {})
  @stores.capture_first {|s| s.writable?(key, parameters, conditions)}
end
write(key, data = nil, parameters = {}, conditions = {}) click to toggle source

persists the data so that it can be retrieved by the key & parameters. returns nil if it is unable to persist the data. returns true if successful.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 31
def write(key, data = nil, parameters = {}, conditions = {})
  @stores.capture_first {|s| s.write(key, data, parameters, conditions)}
end
write_all(key, data = nil, parameters = {}, conditions = {}) click to toggle source

persists the data to all context stores. returns nil if none of the stores were able to persist the data. returns true if at least one write was successful.

# File lib/merb-cache/stores/strategy/adhoc_store.rb, line 38
def write_all(key, data = nil, parameters = {}, conditions = {})
  @stores.map {|s| s.write_all(key, data, parameters, conditions)}.all?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.