Class: Merb::Cache::AbstractStrategyStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- Merb::Cache::AbstractStrategyStore
- Defined in:
- merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb
Overview
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 its 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.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) stores
Returns the value of attribute stores.
Class Method Summary (collapse)
- + (Object) contextualize(*stores) (also: []) private
Instance Method Summary (collapse)
- - (Object) clone
-
- (Object) delete(key, parameters = {})
Deletes the entry for the key & parameter from the store.
-
- (Object) delete_all!
Deletes all entries for the key & parameters for the store.
-
- (Boolean?) exists?(key, parameters = {})
Returns true/false/nil based on if data identified by the key & parameters is persisted in the store.
-
- (Object) fetch(key, parameters = {}, conditions = {}) { ... }
Tries to read the data from the store.
-
- (AbstractStrategyStore) initialize(config = {})
constructor
A new instance of AbstractStrategyStore.
-
- (Object?) read(key, parameters = {})
Gets the data from the store identified by the key & parameters.
-
- (Boolean) writable?(key, parameters = {}, conditions = {})
Determines if the store is able to persist data identified by the key & parameters with the given conditions.
-
- (Boolean?) write(key, data = nil, parameters = {}, conditions = {})
Persists the data so that it can be retrieved by the key & parameters.
-
- (true?) write_all(key, data = nil, parameters = {}, conditions = {})
Persists the data to all context stores.
Methods inherited from AbstractStore
Constructor Details
- (AbstractStrategyStore) initialize(config = {})
A new instance of AbstractStrategyStore
52 53 54 55 56 57 58 59 60 61 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 52 def initialize(config = {}) @stores = contextualized_stores.map do |cs| case cs when Symbol Merb::Cache[cs] when Class cs.new(config) end end end |
Instance Attribute Details
- (Object) stores
Returns the value of attribute stores
50 51 52 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 50 def stores @stores end |
Class Method Details
+ (Object) contextualize(*stores) Also known as: []
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 38 def self.contextualize(*stores) Class.new(self) do cattr_accessor :contextualized_stores self.contextualized_stores = stores end end |
Instance Method Details
- (Object) clone
129 130 131 132 133 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 129 def clone twin = super twin.stores = self.stores.map {|s| s.clone} twin end |
- (Object) delete(key, parameters = {})
Deletes the entry for the key & parameter from the store.
118 119 120 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 118 def delete(key, parameters = {}) raise NotImplementedError end |
- (Object) delete_all!
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 entries.
125 126 127 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 125 def delete_all! raise NotImplementedError end |
- (Boolean?) exists?(key, parameters = {})
Returns true/false/nil based on if data identified by the key & parameters is persisted in the store.
113 114 115 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 113 def exists?(key, parameters = {}) raise NotImplementedError end |
- (Object) fetch(key, parameters = {}, conditions = {}) { ... }
Tries to read the data from the store. If that fails, it calls the block parameter and persists the result.
105 106 107 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 105 def fetch(key, parameters = {}, conditions = {}, &blk) raise NotImplementedError end |
- (Object?) read(key, parameters = {})
Gets the data from the store identified by the key & parameters.
77 78 79 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 77 def read(key, parameters = {}) raise NotImplementedError end |
- (Boolean) writable?(key, parameters = {}, conditions = {})
Determines if the store is able to persist data identified by the key & parameters with the given conditions.
70 71 72 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 70 def writable?(key, parameters = {}, conditions = {}) raise NotImplementedError end |
- (Boolean?) write(key, data = nil, parameters = {}, conditions = {})
Persists the data so that it can be retrieved by the key & parameters. returns nil if it is unable to persist the data.
86 87 88 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 86 def write(key, data = nil, parameters = {}, conditions = {}) raise NotImplementedError end |
- (true?) write_all(key, data = nil, parameters = {}, conditions = {})
Persists the data to all context stores.
94 95 96 |
# File 'merb-cache/lib/merb-cache/stores/strategy/abstract_strategy_store.rb', line 94 def write_all(key, data = nil, parameters = {}, conditions = {}) raise NotImplementedError end |