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 |
# File 'lib/lacquer/cache_utils.rb', line 3 def self.included(base) base.class_eval do attr_reader :cache_ttl before_filter :set_default_cache_ttl after_filter :send_cache_control_headers 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/*’)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lacquer/cache_utils.rb', line 26 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('url.purge ' << path)) when :resque require 'lacquer/resque_job' Resque.enqueue(Lacquer::ResqueJob, 'url.purge ' << path) when :none Varnish.new.purge('url.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.
44 45 46 47 48 |
# File 'lib/lacquer/cache_utils.rb', line 44 def send_cache_control_headers if Lacquer.configuration.enable_cache && @cache_ttl && @cache_ttl != 0 expires_in(@cache_ttl, :public => true, :private => false) end end |
#set_cache_ttl(ttl) ⇒ Object
Instance variable for the action ttl.
13 14 15 |
# File 'lib/lacquer/cache_utils.rb', line 13 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.
19 20 21 |
# File 'lib/lacquer/cache_utils.rb', line 19 def set_default_cache_ttl set_cache_ttl(Lacquer.configuration.default_ttl) end |