faraday-http-cache 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/faraday/http_cache/strategies/by_url.rb +7 -1
- data/lib/faraday/http_cache.rb +2 -0
- data/spec/strategies/by_url_spec.rb +41 -0
- metadata +19 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5716c34ddc27f6cd3c0e4956752da967696e7d5a513c3f6f532c27757817b89
|
|
4
|
+
data.tar.gz: dca0a5f6055eb9e30efadb921d339e827feb49bbe76c2d6188a08599d1a6f534
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 220e972ce9da74fbfda0a8a1885470828535adbe58763f59d8da0ecd46be8f66633f5f3e29ad75ab3c5178c9c2566d7c195a138bcf899e842b41535051dbec1d
|
|
7
|
+
data.tar.gz: e05520d225a5cccdb0b4088fbb11ebc5e61f7cd91cbc12aca50df558da5651e5429a34a5da46fe332ac85109750f385b4963d4b55767ede9f8261df8db9d8ed8
|
|
@@ -10,6 +10,11 @@ module Faraday
|
|
|
10
10
|
# The original strategy by Faraday::HttpCache.
|
|
11
11
|
# Uses URL + HTTP method to generate cache keys.
|
|
12
12
|
class ByUrl < BaseStrategy
|
|
13
|
+
def initialize(options = {})
|
|
14
|
+
super
|
|
15
|
+
@max_entries = options[:max_entries]
|
|
16
|
+
end
|
|
17
|
+
|
|
13
18
|
# Store a response inside the cache.
|
|
14
19
|
#
|
|
15
20
|
# @param [Faraday::HttpCache::Request] request - instance of the executed HTTP request.
|
|
@@ -26,6 +31,7 @@ module Faraday
|
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
entries << entry
|
|
34
|
+
entries = entries.last(@max_entries) unless @max_entries.nil?
|
|
29
35
|
|
|
30
36
|
cache.write(key, entries)
|
|
31
37
|
rescue ::Encoding::UndefinedConversionError => e
|
|
@@ -99,7 +105,7 @@ module Faraday
|
|
|
99
105
|
vary = headers['Vary'].to_s
|
|
100
106
|
|
|
101
107
|
vary.empty? || (vary != '*' && vary.split(/[\s,]+/).all? do |header|
|
|
102
|
-
request.headers[header] == cached_request[:headers][header]
|
|
108
|
+
request.headers[header] == (cached_request[:headers][header] || cached_request[:headers][header.downcase])
|
|
103
109
|
end)
|
|
104
110
|
end
|
|
105
111
|
|
data/lib/faraday/http_cache.rb
CHANGED
|
@@ -85,6 +85,8 @@ module Faraday
|
|
|
85
85
|
# :instrumenter - An instrumentation object that should respond to 'instrument'.
|
|
86
86
|
# :instrument_name - The String name of the instrument being reported on (optional).
|
|
87
87
|
# :logger - A logger object.
|
|
88
|
+
# :max_entries - The maximum number of entries to store per cache key. This option is only
|
|
89
|
+
# used when using the +ByUrl+ cache strategy.
|
|
88
90
|
#
|
|
89
91
|
# Examples:
|
|
90
92
|
#
|
|
@@ -29,6 +29,29 @@ describe Faraday::HttpCache::Strategies::ByUrl do
|
|
|
29
29
|
described_class.new(store: wrong)
|
|
30
30
|
}.to raise_error(ArgumentError)
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
context 'with max_entries set' do
|
|
34
|
+
let(:max_entries) { 2 }
|
|
35
|
+
let(:strategy) { described_class.new(store: cache, max_entries: max_entries) }
|
|
36
|
+
let(:response) { double(serializable_hash: { response_headers: { 'Vary' => 'X-Foo' } }) }
|
|
37
|
+
|
|
38
|
+
it 'limits the number of cached entries' do
|
|
39
|
+
requests = Array.new(max_entries + 1) do |i|
|
|
40
|
+
env = { method: :get, url: 'http://test/index', headers: { 'X-Foo' => i } }
|
|
41
|
+
double(env.merge(serializable_hash: env))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
requests.each { |request| subject.write(request, response) }
|
|
45
|
+
|
|
46
|
+
expect(subject.cache.read(cache_key).count).to eq(max_entries)
|
|
47
|
+
|
|
48
|
+
expect(subject.read(requests.first)).to eq(nil)
|
|
49
|
+
|
|
50
|
+
requests.last(max_entries).each do |request|
|
|
51
|
+
expect(subject.read(request)).not_to be_nil
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
32
55
|
end
|
|
33
56
|
|
|
34
57
|
describe 'storing responses' do
|
|
@@ -86,6 +109,24 @@ describe Faraday::HttpCache::Strategies::ByUrl do
|
|
|
86
109
|
|
|
87
110
|
expect(subject.read(request)).to be_a(Faraday::HttpCache::Response)
|
|
88
111
|
end
|
|
112
|
+
|
|
113
|
+
context 'with a Vary header in the response in a different case than the matching request header' do
|
|
114
|
+
let(:request) do
|
|
115
|
+
Faraday::HttpCache::Request.new(
|
|
116
|
+
method: :get,
|
|
117
|
+
url: 'http://test/index',
|
|
118
|
+
headers: Faraday::Utils::Headers.new({ 'accept' => 'application/json' })
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
let(:response) do
|
|
122
|
+
Faraday::HttpCache::Response.new(response_headers: Faraday::Utils::Headers.new({ vary: 'Accept' }))
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it 'reads stored message' do
|
|
126
|
+
subject.write(request, response)
|
|
127
|
+
expect(subject.read(request)).to be_a(Faraday::HttpCache::Response)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
89
130
|
end
|
|
90
131
|
|
|
91
132
|
context 'with the JSON serializer' do
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faraday-http-cache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lucas Mazza
|
|
8
8
|
- George Guimarães
|
|
9
9
|
- Gustavo Araujo
|
|
10
|
-
autorequire:
|
|
10
|
+
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2026-01-19 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: faraday
|
|
@@ -66,7 +66,7 @@ homepage: https://github.com/sourcelevel/faraday-http-cache
|
|
|
66
66
|
licenses:
|
|
67
67
|
- Apache-2.0
|
|
68
68
|
metadata: {}
|
|
69
|
-
post_install_message:
|
|
69
|
+
post_install_message:
|
|
70
70
|
rdoc_options: []
|
|
71
71
|
require_paths:
|
|
72
72
|
- lib
|
|
@@ -74,31 +74,31 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
74
74
|
requirements:
|
|
75
75
|
- - ">="
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: 2.
|
|
77
|
+
version: 3.2.0
|
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
83
|
requirements: []
|
|
84
|
-
rubygems_version: 3.
|
|
85
|
-
signing_key:
|
|
84
|
+
rubygems_version: 3.0.3.1
|
|
85
|
+
signing_key:
|
|
86
86
|
specification_version: 4
|
|
87
87
|
summary: A Faraday middleware that stores and validates cache expiration.
|
|
88
88
|
test_files:
|
|
89
|
-
- spec/binary_spec.rb
|
|
90
|
-
- spec/cache_control_spec.rb
|
|
91
|
-
- spec/http_cache_spec.rb
|
|
92
|
-
- spec/instrumentation_spec.rb
|
|
93
|
-
- spec/json_spec.rb
|
|
94
|
-
- spec/request_spec.rb
|
|
95
|
-
- spec/response_spec.rb
|
|
96
89
|
- spec/spec_helper.rb
|
|
97
|
-
- spec/
|
|
98
|
-
- spec/strategies/base_strategy_spec.rb
|
|
99
|
-
- spec/strategies/by_url_spec.rb
|
|
90
|
+
- spec/validation_spec.rb
|
|
100
91
|
- spec/strategies/by_vary_spec.rb
|
|
101
|
-
- spec/
|
|
92
|
+
- spec/strategies/by_url_spec.rb
|
|
93
|
+
- spec/strategies/base_strategy_spec.rb
|
|
94
|
+
- spec/json_spec.rb
|
|
95
|
+
- spec/instrumentation_spec.rb
|
|
96
|
+
- spec/storage_spec.rb
|
|
97
|
+
- spec/http_cache_spec.rb
|
|
98
|
+
- spec/binary_spec.rb
|
|
102
99
|
- spec/support/test_app.rb
|
|
100
|
+
- spec/support/empty.png
|
|
103
101
|
- spec/support/test_server.rb
|
|
104
|
-
- spec/
|
|
102
|
+
- spec/request_spec.rb
|
|
103
|
+
- spec/cache_control_spec.rb
|
|
104
|
+
- spec/response_spec.rb
|