Class: Lacquer::CacheControl
- Inherits:
-
Object
- Object
- Lacquer::CacheControl
show all
- Includes:
- CacheUtils
- Defined in:
- lib/lacquer/cache_control.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from CacheUtils
#clear_cache_for, included, #send_cache_control_headers, #set_cache_ttl, #set_default_cache_ttl
Constructor Details
Returns a new instance of CacheControl.
10
11
12
|
# File 'lib/lacquer/cache_control.rb', line 10
def initialize
self.store = []
end
|
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
8
9
10
|
# File 'lib/lacquer/cache_control.rb', line 8
def store
@store
end
|
Instance Method Details
20
21
22
|
# File 'lib/lacquer/cache_control.rb', line 20
def configure
yield self
end
|
#purge(group, *args) ⇒ Object
24
25
26
|
# File 'lib/lacquer/cache_control.rb', line 24
def purge(group, *args)
clear_cache_for(*urls_for(group, *args))
end
|
#register(group, options = {}) ⇒ Object
14
15
16
17
18
|
# File 'lib/lacquer/cache_control.rb', line 14
def register(group, options = {})
options[:group] = group
options[:args] = Array(options[:args]).compact
store << options
end
|
#to_vcl_conditions(urls = store) ⇒ Object
33
34
35
|
# File 'lib/lacquer/cache_control.rb', line 33
def to_vcl_conditions(urls = store)
urls.map { |opt| %Q[req.url ~ "#{(opt[:url] % opt[:args])}"] }.join(" || ")
end
|
#to_vcl_override_ttl_urls ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lacquer/cache_control.rb', line 37
def to_vcl_override_ttl_urls
urls_grouped_by_expires.map do |expires_in, list|
<<-CODE.gsub(/^[ \t]{4}*/, '')
if(#{to_vcl_conditions(list)}) {
unset beresp.http.Set-Cookie;
set beresp.ttl = #{expires_in};
return(deliver);
}
CODE
end.join("\n")
end
|
#to_vcl_pass_urls ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/lacquer/cache_control.rb', line 49
def to_vcl_pass_urls
<<-CODE.gsub(/^[ \t]{4}*/, '')
if(#{to_vcl_conditions(urls_by(:pass))}) {
return(pass);
}
CODE
end
|
#to_vcl_pipe_urls ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/lacquer/cache_control.rb', line 57
def to_vcl_pipe_urls
<<-CODE.gsub(/^[ \t]{4}*/, '')
if(#{to_vcl_conditions(urls_by(:pipe))}) {
return(pipe);
}
CODE
end
|
#urls_for(group, *args) ⇒ Object
28
29
30
31
|
# File 'lib/lacquer/cache_control.rb', line 28
def urls_for(group, *args)
args.map! { |arg| arg.to_param }
urls_by(group).map { |options| options[:url] % args }
end
|