Sha256: 4def6deef34bb09205aca35ebc2fd2de20122e6b9071b5b2e8aa07a798185de5

Contents?: true

Size: 743 Bytes

Versions: 26

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

require "pathname"
require_relative "store"

module HTTPX::Plugins
  module ResponseCache
    class FileStore < Store
      def initialize(dir = Dir.tmpdir)
        @dir = Pathname.new(dir)
      end

      def clear
        # delete all files
      end

      def cached?(request)
        file_path = @dir.join(request.response_cache_key)

        exist?(file_path)
      end

      private

      def _get(request)
        return unless cached?(request)

        File.open(@dir.join(request.response_cache_key))
      end

      def _set(request, response)
        file_path = @dir.join(request.response_cache_key)

        response.copy_to(file_path)

        response.body.rewind
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.3.3 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.3.2 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.3.1 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.3.0 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.6 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.4 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.3 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.2 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.1 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.2.0 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.5 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.4 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.3 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.2 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.1 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.1.0 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.0.2 lib/httpx/plugins/response_cache/file_store.rb
httpx-0.24.7 lib/httpx/plugins/response_cache/file_store.rb
httpx-1.0.1 lib/httpx/plugins/response_cache/file_store.rb