Class: SeoCache::PopulateCache

Inherits:
Object
  • Object
show all
Defined in:
lib/seo_cache/populate_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, paths, options = {}) ⇒ PopulateCache

Returns a new instance of PopulateCache.



8
9
10
11
12
13
14
15
# File 'lib/seo_cache/populate_cache.rb', line 8

def initialize(host, paths, options = {})
  @host         = host
  @paths        = paths
  @page_render  = PageRender.new
  @page_caching = PageCaching.new

  @force_cache = options.fetch(:force_cache, false)
end

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/seo_cache/populate_cache.rb', line 17

def perform
  @paths.each do |path|
    next if @page_caching.cache_exists?(path) && !@force_cache

    url = @host + path
    url += if path.include?('?')
             '&'
           else
             '?'
           end
    url += "#{SeoCache.prerender_url_param}=true"

    page_source = @page_render.get(url, false)
    @page_caching.cache(page_source, path)
  end

ensure
  @page_render.close_connection
end