Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created March 20, 2020 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr33n7007h/ed075f2b9fc6eccbadb52f0671309854 to your computer and use it in GitHub Desktop.
Save gr33n7007h/ed075f2b9fc6eccbadb52f0671309854 to your computer and use it in GitHub Desktop.
require 'typhoeus'
class Cache
def initialize
@memory = {}
end
def get(request)
@memory[request]
end
def set(request, response)
@memory[request] = response
end
end
Typhoeus::Config.cache = Cache.new
p Typhoeus.get('www.example.com', cache_ttl: 1).cached? #=> false
Kernel.sleep(2)
p Typhoeus.get('www.example.com').cached? # this would be true without cache_ttl #=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment