class Typhoeus::Cache::Redis
This module provides a simple way to cache HTTP responses in Redis.
def get(request)
def get(request) serialized_response = @redis.get(request.cache_key) return unless serialized_response Marshal.load(serialized_response) end
def initialize(redis = ::Redis.new, options = {})
(**options)
-
:default_ttl
(Integer
) --
Parameters:
-
options
(Hash
) -- -
redis
(Redis
) --
Other tags:
- Example: Set Redis as the Typhoeus cache backend -
def initialize(redis = ::Redis.new, options = {}) @redis = redis @default_ttl = options[:default_ttl] end
def set(request, response)
def set(request, response) ttl = request.cache_ttl || @default_ttl key = request.cache_key serialized_response = Marshal.dump(response) @redis.set(key, serialized_response) @redis.expire(key, ttl) if ttl end