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