Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

faraday-http-cache

> 编程语言
Open source

A Faraday middleware that respects HTTP cache

346 stars0 likes3 views
WebsiteGitHub

About

A Faraday middleware that respects HTTP cache

Faraday Http Cache

A Faraday middleware that respects HTTP cache, by checking expiration and validation of the stored responses.

Installation

Add it to your Gemfile:

ruby
gem 'faraday-http-cache'

Usage and configuration

You have to use the middleware in the Faraday instance that you want to, along with a suitable store to cache the responses. You can use the new shortcut using a symbol or passing the middleware class

ruby
client = Faraday.new do |builder|
  builder.use :http_cache, store: Rails.cache
  # or
  builder.use Faraday::HttpCache, store: Rails.cache

  builder.adapter Faraday.default_adapter
end

The middleware accepts a store option for the cache backend responsible for recording the API responses that should be stored. Stores should respond to write, read and delete, just like an object from the ActiveSupport::Cache API.

ruby
# Connect the middleware to a Memcache instance.
store = ActiveSupport::Cache.lookup_store(:mem_cache_store, ['localhost:11211'])

client = Faraday.new do |builder|
  builder.use :http_cache, store: store
  builder.adapter Faraday.default_adapter
end

# Or use the Rails.cache instance inside your Rails app.
client = Faraday.new do |builder|
  builder.use :http_cache, store: Rails.cache
  builder.adapter Faraday.default_adapter
end

The default store provided is a simple in memory cache that lives on the client instance. This type of store might not be persisted across multiple processes or connection instances so it is probably not suitable for most production environments. Make sure that you configure a store that is suitable for you.

The stdlib JSON module is used for serialization by default, which can struggle with unicode characters in responses in Ruby will be cached


## License

Copyright (c) 2012-2018 Plataformatec.
Copyright (c) 2019 SourceLevel and contributors.

  [marshal]: https://www.ruby-doc.org/core-3.0/Marshal.html

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubycachefaradayhttpmiddleware

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言