Class: Lacquer::CacheControl

Inherits:
Object
  • Object
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

#initializeCacheControl

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

#storeObject

Returns the value of attribute store.



8
9
10
# File 'lib/lacquer/cache_control.rb', line 8

def store
  @store
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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_urlsObject



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|
    "    if(\#{to_vcl_conditions(list)}) {\n      unset beresp.http.Set-Cookie;\n      set beresp.ttl = \#{expires_in};\n      return(deliver);\n    }\n    CODE\n  end.join(\"\\n\")\nend\n".gsub(/^[ \t]{4}*/, '')

#to_vcl_pass_urlsObject



49
50
51
52
53
54
55
# File 'lib/lacquer/cache_control.rb', line 49

def to_vcl_pass_urls
  "  if(\#{to_vcl_conditions(urls_by(:pass))}) {\n    return(pass);\n  }\n  CODE\nend\n".gsub(/^[ \t]{4}*/, '')

#to_vcl_pipe_urlsObject



57
58
59
60
61
62
63
# File 'lib/lacquer/cache_control.rb', line 57

def to_vcl_pipe_urls
  "  if(\#{to_vcl_conditions(urls_by(:pipe))}) {\n    return(pipe);\n  }\n  CODE\nend\n".gsub(/^[ \t]{4}*/, '')

#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