Module: Varnish

Defined in:
lib/varnish.rb

Instance Method Summary collapse

Instance Method Details

#make_cacheable(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/varnish.rb', line 3

def make_cacheable(options = {})
  if should_be_cached?(options)
    headers['Cache-Control'] = cache_control_text(options)
  end

  if options[:depends_on] && request.headers['X_VARNISH']
    remember_url_for_obj(request.url, options)
  end
end

#sweep_cache_for(obj, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/varnish.rb', line 13

def sweep_cache_for(obj, options = {})
  return unless obj
  # cache_data is a frozen hash
  if (cache_data = Rails.cache.read( varnish_cache_key(obj))) || options[:urls]
    Rails.cache.delete( varnish_cache_key(obj) )
    if cache_data
      urls = cache_data[:urls].to_a + options[:urls].to_a
    else
      urls = options[:urls].to_a
    end
    
    if options[:instant]
      SweeperJob.perform(urls)
    else
      Resque.enqueue(SweeperJob, urls)
    end
    urls
  end
end