Module: Lacquer::CacheUtils
- Defined in:
- lib/lacquer/cache_utils.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#clear_cache_for(*paths) ⇒ Object
Sends url.purge command to varnish to clear cache.
-
#send_cache_control_headers ⇒ Object
Sends cache control headers with page.
-
#set_cache_ttl(ttl) ⇒ Object
Instance variable for the action ttl.
-
#set_default_cache_ttl ⇒ Object
Called as a before filter to set default ttl for the entire application.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/lacquer/cache_utils.rb', line 3 def self.included(base) base.class_eval do attr_reader :cache_ttl if respond_to? :before_filter before_filter :set_default_cache_ttl after_filter :send_cache_control_headers end end end |
Instance Method Details
#clear_cache_for(*paths) ⇒ Object
Sends url.purge command to varnish to clear cache.
clear_cache_for(root_path, blog_posts_path, ‘/other/content/*’)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lacquer/cache_utils.rb', line 28 def clear_cache_for(*paths) paths.each do |path| case Lacquer.configuration.job_backend when :delayed_job require 'lacquer/delayed_job_job' Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(path)) when :resque require 'lacquer/resque_job' Resque.enqueue(Lacquer::ResqueJob, path) when :none Varnish.new.purge(path) end end end |
#send_cache_control_headers ⇒ Object
Sends cache control headers with page. These are the headers that varnish responds to to set cache properly.
46 47 48 49 50 |
# File 'lib/lacquer/cache_utils.rb', line 46 def send_cache_control_headers if Lacquer.configuration.enable_cache && @cache_ttl && @cache_ttl != 0 expires_in(@cache_ttl, :public => true) end end |
#set_cache_ttl(ttl) ⇒ Object
Instance variable for the action ttl.
15 16 17 |
# File 'lib/lacquer/cache_utils.rb', line 15 def set_cache_ttl(ttl) @cache_ttl = ttl end |
#set_default_cache_ttl ⇒ Object
Called as a before filter to set default ttl for the entire application.
21 22 23 |
# File 'lib/lacquer/cache_utils.rb', line 21 def set_default_cache_ttl set_cache_ttl(Lacquer.configuration.default_ttl) end |