Faraday Http Cache 介绍
Faraday Http Cache 是一个 Faraday 的扩展,实现了
HTTP 的缓存。通过检查过期时间来验证已存储的响应信息。
使用方法:
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
使用 Memcached:
# 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
日志:
client = Faraday.new do |builder| builder.use :http_cache, store: Rails.cache, logger: Rails.logger builder.adapter Faraday.default_adapter end client.get('http://site/api/users') # logs "HTTP Cache: [GET users] miss, store"
Faraday Http Cache 官网
https://github.com/plataformatec/faraday-http-cache
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。