class Typhoeus::Cache::Dalli
This module provides a simple way to cache HTTP responses using Dalli.
Public Class Methods
new(client = ::Dalli::Client.new, options = {})
click to toggle source
@example Set Dalli as the Typhoeus cache backend
Typhoeus::Config.cache = Typhoeus::Cache::Dalli.new
@param [ Dalli::Client ] client
A connection to the cache server. Defaults to `Dalli::Client.new`
@param [ Hash ] options
Options
@option options [ Integer ] :default_ttl
The default TTL of cached responses in seconds, for requests which do not set a cache_ttl.
# File lib/typhoeus/cache/dalli.rb, line 14 def initialize(client = ::Dalli::Client.new, options = {}) @client = client @default_ttl = options[:default_ttl] end
Public Instance Methods
get(request)
click to toggle source
# File lib/typhoeus/cache/dalli.rb, line 19 def get(request) @client.get(request.cache_key) end
set(request, response)
click to toggle source
# File lib/typhoeus/cache/dalli.rb, line 23 def set(request, response) @client.set(request.cache_key, response, request.cache_ttl || @default_ttl) end