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