Class: Typhoeus::Cache::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus/cache/rails.rb

Overview

This module provides a simple way to cache HTTP responses in using the Rails cache.

Since:

  • 0.5.0

Instance Method Summary collapse

Constructor Details

#initialize(cache = ::Rails.cache, options = {}) ⇒ Rails

Returns a new instance of Rails

Examples:

Use the Rails cache setup to cache Typhoeus responses.

Typhoeus::Config.cache = Typhoeus::Cache::Rails.new

Since:

  • 0.5.0


12
13
14
15
# File 'lib/typhoeus/cache/rails.rb', line 12

def initialize(cache = ::Rails.cache, options = {})
  @cache = cache
  @default_ttl = options[:default_ttl]
end

Instance Method Details

#get(request) ⇒ Object

Since:

  • 0.5.0


17
18
19
# File 'lib/typhoeus/cache/rails.rb', line 17

def get(request)
  @cache.read(request)
end

#set(request, response) ⇒ Object

Since:

  • 0.5.0


21
22
23
# File 'lib/typhoeus/cache/rails.rb', line 21

def set(request, response)
  @cache.write(request, response, :expires_in => request.cache_ttl || @default_ttl)
end