faraday-http-cache 2.5.1 → 2.6.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d83bc178f6be84f8807a6357f4d60aefbdde828a0b63355b4517aa7a2e3dca0
|
|
4
|
+
data.tar.gz: d1543b1549fc3924d15bba59947f7b46aa05609043328f7ce84bec56cea16e45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 863ec060abd499c032a62be09cbb4ac5c0d00529a3af5c2ffff79c2c538eb56adbb4b2932eb3be55670f00777fe887383398b64cb457510a8a822176367e9040
|
|
7
|
+
data.tar.gz: 5817a00b39242a99cd7539b2bf883606faa68bad7aba448e7dda23490de02ee9de3814b6f7b3932edf1d86e7d66cd011badc8a637fa7725ca0e89cb018b6a9aa
|
|
@@ -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
|
data/lib/faraday/http_cache.rb
CHANGED
|
@@ -48,7 +48,7 @@ module Faraday
|
|
|
48
48
|
class HttpCache < Faraday::Middleware
|
|
49
49
|
UNSAFE_METHODS = %i[post put delete patch].freeze
|
|
50
50
|
|
|
51
|
-
ERROR_STATUSES = (400..499)
|
|
51
|
+
ERROR_STATUSES = (400..499)
|
|
52
52
|
|
|
53
53
|
# The name of the instrumentation event.
|
|
54
54
|
EVENT_NAME = 'http_cache.faraday'
|
|
@@ -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
|
data/spec/support/test_server.rb
CHANGED
|
@@ -32,7 +32,8 @@ class TestServer
|
|
|
32
32
|
Logger: WEBrick::Log.new(log),
|
|
33
33
|
AccessLog: [[log, '[%{X-Faraday-Adapter}i] %m %U -> %s %b']]
|
|
34
34
|
}
|
|
35
|
-
Rack::Handler::WEBrick
|
|
35
|
+
handler = defined?(Rackup::Handler) ? Rackup::Handler::WEBrick : Rack::Handler::WEBrick
|
|
36
|
+
handler.run(TestApp, **webrick_opts)
|
|
36
37
|
end
|
|
37
38
|
end
|
|
38
39
|
|
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.1
|
|
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
|