From a71765034ba7ead6beb509c32f71091bc34ddc09 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Fri, 1 Mar 2013 15:20:53 +0100 Subject: [PATCH] Request#cache_key implementation --- lib/common/typhoeus_cache.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/common/typhoeus_cache.rb b/lib/common/typhoeus_cache.rb index 811a419a..de21de8d 100644 --- a/lib/common/typhoeus_cache.rb +++ b/lib/common/typhoeus_cache.rb @@ -19,14 +19,26 @@ require 'common/cache_file_store' +# Implementaion of a cache_key (Request:hash cannot be used as such) +# See https://github.com/typhoeus/typhoeus/issues/277 +module Typhoeus + class Request + module Cacheable + def cache_key + Digest::SHA2.hexdigest("#{url}-#{options[:body]}-#{options[:method]}") + end + end + end +end + class TyphoeusCache < CacheFileStore def get(request) - read_entry(request.hash.to_s) + read_entry(request.cache_key) end def set(request, response) - write_entry(request.hash.to_s, response, request.cache_ttl) + write_entry(request.cache_key, response, request.cache_ttl) end end