Class: Merb::Cache::MintCacheStore

Inherits:
AbstractStrategyStore
  • Object
show all
Defined in:
lib/merb-cache/stores/strategy/mintcache_store.rb

Instance Method Summary collapse

Instance Method Details

#delete(key, parameters = {}) ⇒ Object



42
43
44
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 42

def delete(key, parameters = {})
  [key, validity_key(key), data_key(key)].map{|k| @stores.map {|c| c.delete(k, parameters)} }.flatten.any?
end

#delete_all!Object



46
47
48
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 46

def delete_all!
  @stores.map {|c| c.delete_all! }.all?
end

#exists?(key, parameters = {}) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 38

def exists?(key, parameters = {})
  @stores.any?{|store| store.exists?(key, parameters)} || @stores.any? {|store| store.exists?(validity_key(key), parameters)}
end

#fetch(key, parameters = {}, conditions = {}, &blk) ⇒ Object



32
33
34
35
36
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 32

def fetch(key, parameters = {}, conditions = {}, &blk)
  wrapper_blk = lambda { blk.call }
  cache_read = read(key, parameters) || @stores.capture_first {|s| s.fetch(key, parameters, conditions, &wrapper_blk)}
  return cache_read || read_mint_cache(key, parameters)
end

#read(key, parameters = {}) ⇒ Object



8
9
10
11
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 8

def read(key, parameters = {})
  cache_read = @stores.capture_first {|c| c.read(key, parameters)}
  return cache_read || read_mint_cache(key, parameters)
end

#writable?(key, parameters = {}, conditions = {}) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 4

def writable?(key, parameters = {}, conditions = {})
  @stores.capture_first {|s| s.writable?(key, parameters, conditions)}
end

#write(key, data = nil, parameters = {}, conditions = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 13

def write(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    write_mint_cache(key, data, parameters, conditions)
    @stores.capture_first {|c| c.write(key, data, parameters, conditions)}
  end
end

#write_all(key, data = nil, parameters = {}, conditions = {}) ⇒ Object

if you’re wrapping multiple stores in a strategy store, it will write to all the wrapped stores, not just the first store that is successful



22
23
24
25
26
27
28
29
30
# File 'lib/merb-cache/stores/strategy/mintcache_store.rb', line 22

def write_all(key, data = nil, parameters = {}, conditions = {})
  if writable?(key, parameters, conditions)
    key_write = @stores.map {|c| c.write_all(key, data, parameters, conditions)}.all?
    validity_write = @stores.map {|c| c.write_all(validity_key(key), data, parameters, conditions)}.all?
    data_write = @stores.map {|c| c.write_all(data_key(key), data, parameters, conditions)}.all?

    return (key_write and validity_write and data_write) ? true : false
  end
end