Class: Merb::Cache::PageStore
Overview
Store well suited for page caching.
Instance Attribute Summary
#stores
Instance Method Summary
collapse
-
#delete(dispatch, parameters = {}) ⇒ Object
-
#delete_all! ⇒ Object
-
#exists?(dispatch, parameters = {}) ⇒ Boolean
-
#fetch(dispatch, parameters = {}, conditions = {}, &blk) ⇒ Object
-
#normalize(dispatch) ⇒ Object
-
#query_string_present?(dispatch) ⇒ Boolean
-
#read(dispatch, parameters = {}) ⇒ Object
-
#writable?(dispatch, parameters = {}, conditions = {}) ⇒ Boolean
-
#write(dispatch, data = nil, parameters = {}, conditions = {}) ⇒ Object
-
#write_all(dispatch, data = nil, parameters = {}, conditions = {}) ⇒ Object
#clone, contextualize, #initialize
#delete_all, #initialize
Instance Method Details
#delete(dispatch, parameters = {}) ⇒ Object
43
44
45
46
47
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 43
def delete(dispatch, parameters = {})
if writable?(dispatch, parameters)
@stores.map {|s| s.delete(normalize(dispatch), {})}.any?
end
end
|
#delete_all! ⇒ Object
49
50
51
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 49
def delete_all!
@stores.map {|s| s.delete_all!}.all?
end
|
#exists?(dispatch, parameters = {}) ⇒ Boolean
37
38
39
40
41
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 37
def exists?(dispatch, parameters = {})
if writable?(dispatch, parameters)
@stores.capture_first {|s| s.exists?(normalize(dispatch), {})}
end
end
|
#fetch(dispatch, parameters = {}, conditions = {}, &blk) ⇒ Object
31
32
33
34
35
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 31
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, {}, conditions, &blk)}
end
end
|
#normalize(dispatch) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 53
def normalize(dispatch)
key = dispatch.request.uri.split('?').first
key << "index" if key =~ /\/$/
key << ".#{dispatch.content_type}" unless key =~ /\.\w{2,6}/
key
end
|
#query_string_present?(dispatch) ⇒ Boolean
60
61
62
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 60
def query_string_present?(dispatch)
dispatch.request.env["REQUEST_URI"] == dispatch.request.uri
end
|
#read(dispatch, parameters = {}) ⇒ Object
15
16
17
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 15
def read(dispatch, parameters = {})
nil
end
|
#writable?(dispatch, parameters = {}, conditions = {}) ⇒ Boolean
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 4
def writable?(dispatch, parameters = {}, conditions = {})
if Merb::Controller === dispatch && dispatch.request.method == :get &&
!dispatch.request.uri.nil? && !dispatch.request.uri.empty? &&
!conditions.has_key?(:if) && !conditions.has_key?(:unless) &&
query_string_present?(dispatch)
@stores.any? {|s| s.writable?(normalize(dispatch), parameters, conditions)}
else
false
end
end
|
#write(dispatch, data = nil, parameters = {}, conditions = {}) ⇒ Object
19
20
21
22
23
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 19
def write(dispatch, data = nil, parameters = {}, conditions = {})
if writable?(dispatch, parameters, conditions)
@stores.capture_first {|s| s.write(normalize(dispatch), data || dispatch.body, {}, conditions)}
end
end
|
#write_all(dispatch, data = nil, parameters = {}, conditions = {}) ⇒ Object
25
26
27
28
29
|
# File 'lib/merb-cache/stores/strategy/page_store.rb', line 25
def write_all(dispatch, data = nil, parameters = {}, conditions = {})
if writable?(dispatch, parameters, conditions)
@stores.map {|s| s.write_all(normalize(dispatch), data || dispatch.body, {}, conditions)}.all?
end
end
|