Merb::Cache::AbstractStrategyStore

A strategy store wraps one or more fundamental stores, acting as a middle man between caching requests.

For example, if you need to save memory on your Memcache server, you could wrap your MemcachedStore with a GzipStore. This would automatically compress the cached data when put into the cache, and decompress it on the way out. You can even wrap strategy caches with other strategy caches. If your key was comprised of sensitive information, like a SSN, you might want to encrypt the key before storage. Wrapping your GzipStore in a SHA1Store would take care of that for you.

The AbstractStore class defines 9 methods as the API:

writable?(key, parameters = {}, conditions = {}) exists?(key, parameters = {}) read(key, parameters = {}) write(key, data = nil, parameters = {}, conditions = {}) write_all(key, data = nil, parameters = {}, conditions = {}) fetch(key, parameters = {}, conditions = {}, &blk) delete(key, parameters = {}) delete_all delete_all!

AbstractStrategyStore implements all of these with the exception of delete_all. If a strategy store can guarantee that calling delete_all on it’s wrapped store(s) will only delete entries populated by the strategy store, it may define the safe version of delete_all. However, this is usually not the case, hence delete_all is not part of the public API for AbstractStrategyStore.

Attributes

stores[RW]
stores[RW]

END: interface for creating strategy stores.

Public Class Methods

contextualize(*stores) click to toggle source

START: interface for creating strategy stores. This should/might change.

    # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 37
37:     def self.contextualize(*stores)
38:       Class.new(self) do
39:         cattr_accessor :contextualized_stores
40: 
41:         self.contextualized_stores = stores
42:       end
43:     end
new(config = {}) click to toggle source
    # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 51
51:     def initialize(config = {})
52:       @stores = contextualized_stores.map do |cs|
53:         case cs
54:         when Symbol
55:           Merb::Cache[cs]
56:         when Class
57:           cs.new(config)
58:         end
59:       end
60:     end

Public Instance Methods

clone() click to toggle source
     # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 116
116:     def clone
117:       twin = super
118:       twin.stores = self.stores.map {|s| s.clone}
119:       twin
120:     end
delete(key, parameters = {}) click to toggle source

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

     # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 105
105:     def delete(key, parameters = {})
106:       raise NotImplementedError
107:     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/abstract_strategy_store.rb, line 112
112:     def delete_all!
113:       raise NotImplementedError
114:     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/abstract_strategy_store.rb, line 100
100:     def exists?(key, parameters = {})
101:       raise NotImplementedError
102:     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.

    # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 94
94:     def fetch(key, parameters = {}, conditions = {}, &blk)
95:       raise NotImplementedError
96:     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/abstract_strategy_store.rb, line 74
74:     def read(key, parameters = {})
75:       raise NotImplementedError
76:     end
writable?(key, parameters = {}, conditions = {}) click to toggle source

determines if the store is able to persist data identified by the key & parameters with the given conditions.

    # File lib/merb-cache/stores/strategy/abstract_strategy_store.rb, line 68
68:     def writable?(key, parameters = {}, conditions = {})
69:       raise NotImplementedError
70:     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/abstract_strategy_store.rb, line 81
81:     def write(key, data = nil, parameters = {}, conditions = {})
82:       raise NotImplementedError
83:     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/abstract_strategy_store.rb, line 88
88:     def write_all(key, data = nil, parameters = {}, conditions = {})
89:       raise NotImplementedError
90:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.