Class: Merb::Cache::ActionStore

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

Overview

Store well suited for action caching.

Instance Method Summary collapse

Instance Method Details

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



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

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

#delete_all!Object



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

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

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

Returns:

  • (Boolean)


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

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

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



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

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

#normalize(dispatch) ⇒ Object



57
58
59
# File 'lib/merb-cache/stores/strategy/action_store.rb', line 57

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

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



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

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

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

If you’re not sending a controller dispatch, then we can’t really write a cache

Returns:

  • (Boolean)


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

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

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



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

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

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



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

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