Class: Merb::Cache::ActionStore

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

Overview

Store well suited for action caching.

Instance Attribute Summary

Attributes inherited from AbstractStrategyStore

#stores

Instance Method Summary collapse

Methods inherited from AbstractStrategyStore

#clone, contextualize, #initialize

Methods inherited from AbstractStore

#delete_all, #initialize

Constructor Details

This class inherits a constructor from Merb::Cache::AbstractStrategyStore

Instance Method Details

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



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

def delete(dispatch, parameters = {})
  if writable?(dispatch, parameters)
    @stores.map {|s| s.delete(normalize(dispatch), parameters)}.any?
  end
end

#delete_all!Object



48
49
50
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 48

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

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



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

def exists?(dispatch, parameters = {})
  if writable?(dispatch, parameters)
    @stores.capture_first {|s| s.exists?(normalize(dispatch), parameters)}
  end
end

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



30
31
32
33
34
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 30

def fetch(dispatch, parameters = {}, conditions = {}, &blk)
  if writable?(dispatch, parameters, conditions)
    read(dispatch, parameters) || @stores.capture_first {|s| s.fetch(normalize(dispatch), data || dispatch.body, parameters, conditions, &blk)}
  end
end

#normalize(dispatch) ⇒ Object



52
53
54
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 52

def normalize(dispatch)
  "#{dispatch.class.name}##{dispatch.action_name}" unless dispatch.class.name.blank? || dispatch.action_name.blank?
end

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



12
13
14
15
16
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 12

def read(dispatch, parameters = {})
  if writable?(dispatch, parameters)
    @stores.capture_first {|s| s.read(normalize(dispatch), parameters)}
  end
end

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



4
5
6
7
8
9
10
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 4

def writable?(dispatch, parameters = {}, conditions = {})
  case dispatch
  when Merb::Controller
    @stores.any?{|s| s.writable?(normalize(dispatch), parameters, conditions)}
  else false
  end
end

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



18
19
20
21
22
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 18

def write(dispatch, data = nil, parameters = {}, conditions = {})
  if writable?(dispatch, parameters, conditions)
    @stores.capture_first {|s| s.write(normalize(dispatch), data || dispatch.body, parameters, conditions)}
  end
end

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



24
25
26
27
28
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 24

def write_all(dispatch, data = nil, parameters = {}, conditions = {})
  if writable?(dispatch, parameters, conditions)
    @stores.map {|s| s.write_all(normalize(dispatch), data || dispatch.body, parameters, conditions)}.all?
  end
end