Sha256: cea8b879beca33f42fddb58ea5f41645f756f58cd4b6d1ff505a60a789048ecf

Contents?: true

Size: 878 Bytes

Versions: 3

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

require 'seo_cache/page_caching'
require 'seo_cache/page_render'

module SeoCache
  class PopulateCache
    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

    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) if page_source
      end

    ensure
      @page_render.close_connection
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seo_cache-1.0.2 lib/seo_cache/populate_cache.rb
seo_cache-1.0.1 lib/seo_cache/populate_cache.rb
seo_cache-1.0.0 lib/seo_cache/populate_cache.rb