faraday-http-cache 1.2.0 → 1.2.2
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.rb +16 -8
- data/spec/http_cache_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a62aee8278ee280538fcda4370c230496f9aa26
|
4
|
+
data.tar.gz: ed354b7f472d84e17c996d2a97c61da81f41bc92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe2d52575496d9f73201deff62c664611c664148a2bde2f01adc1d63074c35ff6dda1103d19171dcb1f114fc1eb563d4235abc7e2439a5d8a6cf0ab88d761a8a
|
7
|
+
data.tar.gz: a7c46d882287552df02f7f3f3baf25c9182ac16c47905bef51520e41895d1baebc81f10ea33798d93c51df85593f16c6829fa7169a71df41c12940f81351986c
|
data/lib/faraday/http_cache.rb
CHANGED
@@ -54,20 +54,26 @@ module Faraday
|
|
54
54
|
EVENT_NAME = 'http_cache.faraday'
|
55
55
|
|
56
56
|
CACHE_STATUSES = [
|
57
|
-
# The request was not cacheable
|
57
|
+
# The request was not cacheable.
|
58
58
|
:unacceptable,
|
59
59
|
|
60
|
-
# The response was cached and can still be used
|
60
|
+
# The response was cached and can still be used.
|
61
61
|
:fresh,
|
62
62
|
|
63
|
-
# The response was cached and the server has validated it with a 304 response
|
63
|
+
# The response was cached and the server has validated it with a 304 response.
|
64
64
|
:valid,
|
65
65
|
|
66
|
-
# The response was
|
66
|
+
# The response was cache but was revalidated by the sserver.
|
67
67
|
:invalid,
|
68
68
|
|
69
|
-
# No response was found in the cache
|
70
|
-
:miss
|
69
|
+
# No response was found in the cache.
|
70
|
+
:miss,
|
71
|
+
|
72
|
+
# The response can't be cached.
|
73
|
+
:uncacheable,
|
74
|
+
|
75
|
+
# The request decided to ignore the cache.
|
76
|
+
:bypass
|
71
77
|
]
|
72
78
|
|
73
79
|
# Public: Initializes a new HttpCache middleware.
|
@@ -243,6 +249,8 @@ module Faraday
|
|
243
249
|
updated_payload[:response_headers].update(updated_response_headers)
|
244
250
|
requested_env.update(updated_payload)
|
245
251
|
response = Response.new(updated_payload)
|
252
|
+
else
|
253
|
+
trace :invalid
|
246
254
|
end
|
247
255
|
store(response)
|
248
256
|
end
|
@@ -259,7 +267,7 @@ module Faraday
|
|
259
267
|
end
|
260
268
|
|
261
269
|
# Internal: Stores the response into the storage.
|
262
|
-
# If the response isn't cacheable, a trace action '
|
270
|
+
# If the response isn't cacheable, a trace action 'uncacheable' will be
|
263
271
|
# recorded for logging purposes.
|
264
272
|
#
|
265
273
|
# response - a 'Faraday::HttpCache::Response' instance to be stored.
|
@@ -270,7 +278,7 @@ module Faraday
|
|
270
278
|
trace :store
|
271
279
|
@storage.write(@request, response)
|
272
280
|
else
|
273
|
-
trace :
|
281
|
+
trace :uncacheable
|
274
282
|
end
|
275
283
|
end
|
276
284
|
|
data/spec/http_cache_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe Faraday::HttpCache do
|
|
28
28
|
client.post('post').body
|
29
29
|
end
|
30
30
|
|
31
|
-
it 'does not cache responses with
|
31
|
+
it 'does not cache responses with , status code' do
|
32
32
|
client.get('broken')
|
33
33
|
expect(client.get('broken').body).to eq('2')
|
34
34
|
end
|
@@ -89,8 +89,8 @@ describe Faraday::HttpCache do
|
|
89
89
|
client.patch('counter')
|
90
90
|
end
|
91
91
|
|
92
|
-
it 'logs that a response with a bad status code is
|
93
|
-
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /broken] miss,
|
92
|
+
it 'logs that a response with a bad status code is uncacheable' do
|
93
|
+
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /broken] miss, uncacheable') }
|
94
94
|
client.get('broken')
|
95
95
|
end
|
96
96
|
|
@@ -115,8 +115,8 @@ describe Faraday::HttpCache do
|
|
115
115
|
expect(client.get('private').body).to eq('2')
|
116
116
|
end
|
117
117
|
|
118
|
-
it 'logs that a private response is
|
119
|
-
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /private] miss,
|
118
|
+
it 'logs that a private response is uncacheable' do
|
119
|
+
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /private] miss, uncacheable') }
|
120
120
|
client.get('private')
|
121
121
|
end
|
122
122
|
end
|
@@ -140,8 +140,8 @@ describe Faraday::HttpCache do
|
|
140
140
|
expect(client.get('dontstore').body).to eq('2')
|
141
141
|
end
|
142
142
|
|
143
|
-
it 'logs that a response with a no-store directive is
|
144
|
-
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /dontstore] miss,
|
143
|
+
it 'logs that a response with a no-store directive is uncacheable' do
|
144
|
+
expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /dontstore] miss, uncacheable') }
|
145
145
|
client.get('dontstore')
|
146
146
|
end
|
147
147
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-http-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|