Sha256: 207b84c2ed138975b74c62b435a76ecd78a63acedb859279830e3b9d99f31d19

Contents?: true

Size: 951 Bytes

Versions: 6772

Compression:

Stored size: 951 Bytes

Contents

module Typhoeus
  module Cache
    # This module provides a simple way to cache HTTP responses in using the Rails cache.
    class Rails
      # @example Use the Rails cache setup to cache Typhoeus responses.
      #   Typhoeus::Config.cache = Typhoeus::Cache::Rails.new
      #
      # @param [ ActiveSupport::Cache::Store ] cache
      #   A Rails cache backend. Defaults to Rails.cache.
      # @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.
      def initialize(cache = ::Rails.cache, options = {})
        @cache = cache
        @default_ttl = options[:default_ttl]
      end

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

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

Version data entries

6,772 entries across 6,770 versions & 23 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb
cybrid_api_organization_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/typhoeus-1.4.1/lib/typhoeus/cache/rails.rb