faraday-http-cache 2.5.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69e426c03cf04e5a7be4211fbed70c2aa236c3e31655aa9f742ee85351a27d00
4
- data.tar.gz: 6954402565ff5652d96c90bb696c8bb65e8d1dc6178d985d6bbd89171893cb75
3
+ metadata.gz: c5716c34ddc27f6cd3c0e4956752da967696e7d5a513c3f6f532c27757817b89
4
+ data.tar.gz: dca0a5f6055eb9e30efadb921d339e827feb49bbe76c2d6188a08599d1a6f534
5
5
  SHA512:
6
- metadata.gz: 60fedd1b2af68503eaf8b108a196ee237f74285dc12e9f526af3a43929ea297db602f357693fcaa9320b46400d1b4c7f08921ea16ebd8a51cd738d0b71a8b1eb
7
- data.tar.gz: 9eb9c0b6b484099240d29e81bc0335777d895f88c084b29561b2cff9551bf0f36a3afa7aafa096dcadee43cce5d1a9f5583010d461e029b9e4a50257b602b5e5
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
@@ -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
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.5.1
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: 2024-01-16 00:00:00.000000000 Z
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.4.0
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.4.10
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/storage_spec.rb
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/support/empty.png
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/validation_spec.rb
102
+ - spec/request_spec.rb
103
+ - spec/cache_control_spec.rb
104
+ - spec/response_spec.rb