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
14:     def initialize(*names)
15:       @stores = names.map {|n| Merb::Cache[n]}
16:     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
58:     def delete(key, parameters = {})
59:       @stores.map {|s| s.delete(key, parameters)}.any?
60:     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
65:     def delete_all!
66:       @stores.map {|s| s.delete_all!}.all?
67:     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
53:     def exists?(key, parameters = {})
54:       @stores.capture_first {|s| s.exists?(key, parameters)}
55:     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
45:     def fetch(key, parameters = {}, conditions = {}, &blk)
46:       read(key, parameters) ||
47:         @stores.capture_first {|s| s.fetch(key, parameters, conditions, &blk)} ||
48:         blk.call
49:     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
24:     def read(key, parameters = {})
25:       @stores.capture_first {|s| s.read(key, parameters)}
26:     end
writable?(key, parameters = {}, conditions = {}) click to toggle source
    # File lib/merb-cache/stores/strategy/adhoc_store.rb, line 18
18:     def writable?(key, parameters = {}, conditions = {})
19:       @stores.capture_first {|s| s.writable?(key, parameters, conditions)}
20:     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
31:     def write(key, data = nil, parameters = {}, conditions = {})
32:       @stores.capture_first {|s| s.write(key, data, parameters, conditions)}
33:     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
38:     def write_all(key, data = nil, parameters = {}, conditions = {})
39:       @stores.map {|s| s.write_all(key, data, parameters, conditions)}.all?
40:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.