Sha256: 9147f610969ebe1dafb6895c96368771e0ea729950f1a9b6cbd00a5f3334aa39

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 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)
      end

      @page_render.close_connection
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seo_cache-0.18.0 lib/seo_cache/populate_cache.rb