No commit activity in last 3 years
No release in over 3 years
A super simple Faraday cache implementation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
>= 0

Runtime

~> 0.9
 Project Readme

Faraday::ManualCache

IMPORTANT: This gem hasn't been actively maintained in quite some time, I strongly recommend looking into alternatives!

A super simple Faraday cache implementation.

Unlike faraday-http-cache, faraday-manual-cache ignores cache headers in favor of a manually-specified expires_in.

Installation

Add this line to your application's Gemfile:

gem 'faraday-manual-cache'

And then execute:

$ bundle

Or install it yourself as:

$ gem install faraday-manual-cache

Configuration

Create a configuration file and select your memory store class. If you use Rails, just create an initializator.

FaradayManualCache.configure do |config|
  config.memory_store = ActiveSupport::Cache::MemoryStore.new
end

Usage

Super simple example that caches using the default store (MemoryStore) for the default expires_in (30 seconds):

require 'faraday'
require 'faraday-manual-cache'

connection = Faraday.new(url: 'http://example.com') do |builder|
  builder.use :manual_cache
  builder.adapter Faraday.default_adapter
end

The middleware currently takes several options:

  • conditions: Conditional caching (default GET and HEAD requests).
  • cache_key: Key for requests comparison (default URL)
  • expires_in: Cache expiry, in seconds, either as a value or a lambda (default: 30 seconds).
  • logger: Specify a logger to enable logging.

So a more complicated example would be:

require 'faraday'
require 'faraday-manual-cache'

connection = Faraday.new(url: 'http://example.com') do |builder|
  builder.use :manual_cache,
              conditions: ->(env) { env.method == :get },
              cache_key: ->(env) { "prefix-#{env.url}" },
              expires_in: ->(env) { env.status * 10 },
              logger: Rails.logger
  builder.adapter Faraday.default_adapter
end

As with faraday-http-cache it's recommended that faraday-manual-cache be fairly low in the middleware stack.

Contributing

  1. Fork it ( http://github.com/dobs/faraday-manual-cache/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Attribution

Some implementation details taken from faraday-http-cache.

Contributors