faraday-http-cache 1.1.0 → 1.1.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 +4 -4
- data/README.md +1 -1
- data/lib/faraday/http_cache.rb +8 -6
- data/lib/faraday/http_cache/response.rb +3 -3
- data/lib/faraday/http_cache/storage.rb +2 -1
- data/spec/response_spec.rb +8 -2
- 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: 31653854fcef7bc7fb46c6ba9f92e83d5450a681
|
4
|
+
data.tar.gz: 90b06cc78065d338fa1216292eb124ae3f70b18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10e5f35769cff0522aeef88f465dffe522cc4da8e4a8d7719d024c963f05dd09d3ab6ad2404da8586198acff5da94da8287308f015e373f4d081c2d619fc456
|
7
|
+
data.tar.gz: 7429b49fc0db0619cb4c1d87914c2bbb464547c3fd5d581ce2da93e3b0d380a21d0586c38973c2cd39f2fee86b185f0cbd40c9f97d3d06e0d7a6a375884b6218
|
data/README.md
CHANGED
@@ -123,7 +123,7 @@ end
|
|
123
123
|
You can clone this repository, install it's dependencies with Bundler (run `bundle install`) and
|
124
124
|
execute the files under the `examples` directory to see a sample of the middleware usage.
|
125
125
|
|
126
|
-
## What
|
126
|
+
## What gets cached?
|
127
127
|
|
128
128
|
The middleware will use the following headers to make caching decisions:
|
129
129
|
- Cache-Control
|
data/lib/faraday/http_cache.rb
CHANGED
@@ -74,11 +74,12 @@ module Faraday
|
|
74
74
|
#
|
75
75
|
# app - the next endpoint on the 'Faraday' stack.
|
76
76
|
# args - aditional options to setup the logger and the storage.
|
77
|
-
# :logger
|
78
|
-
# :serializer
|
79
|
-
# :shared_cache
|
80
|
-
# :store
|
81
|
-
# :instrumenter
|
77
|
+
# :logger - A logger object.
|
78
|
+
# :serializer - A serializer that should respond to 'dump' and 'load'.
|
79
|
+
# :shared_cache - A flag to mark the middleware as a shared cache or not.
|
80
|
+
# :store - A cache store that should respond to 'read', 'write', and 'delete'.
|
81
|
+
# :instrumenter - An instrumentation object that should respond to 'instrument'.
|
82
|
+
# :instrument_name - The String name of the instrument being reported on (optional).
|
82
83
|
#
|
83
84
|
# Examples:
|
84
85
|
#
|
@@ -102,6 +103,7 @@ module Faraday
|
|
102
103
|
@logger = options[:logger]
|
103
104
|
@shared_cache = options.fetch(:shared_cache, true)
|
104
105
|
@instrumenter = options[:instrumenter]
|
106
|
+
@instrument_name = options.fetch(:instrument_name, EVENT_NAME)
|
105
107
|
@storage = create_storage(options)
|
106
108
|
end
|
107
109
|
|
@@ -341,7 +343,7 @@ module Faraday
|
|
341
343
|
cache_status: extract_status(env[:http_cache_trace])
|
342
344
|
}
|
343
345
|
|
344
|
-
@instrumenter.instrument(
|
346
|
+
@instrumenter.instrument(@instrument_name, payload)
|
345
347
|
end
|
346
348
|
|
347
349
|
# Internal: Extracts the cache status from a trace.
|
@@ -16,7 +16,7 @@ module Faraday
|
|
16
16
|
# * 302 - 'Found'
|
17
17
|
# * 404 - 'Not Found'
|
18
18
|
# * 410 - 'Gone'
|
19
|
-
CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 404, 410]
|
19
|
+
CACHEABLE_STATUS_CODES = [200, 203, 300, 301, 302, 307, 404, 410]
|
20
20
|
|
21
21
|
# Internal: Gets the actual response Hash (status, headers and body).
|
22
22
|
attr_reader :payload
|
@@ -173,9 +173,9 @@ module Faraday
|
|
173
173
|
|
174
174
|
# Internal: Gets the 'Expires' in a Time object.
|
175
175
|
#
|
176
|
-
# Returns the Time object, or nil if the header isn't present.
|
176
|
+
# Returns the Time object, or nil if the header isn't present or isn't RFC 2616 compliant.
|
177
177
|
def expires
|
178
|
-
headers['Expires'] && Time.httpdate(headers['Expires'])
|
178
|
+
@expires ||= headers['Expires'] && Time.httpdate(headers['Expires']) rescue nil
|
179
179
|
end
|
180
180
|
|
181
181
|
# Internal: Gets the 'CacheControl' object.
|
@@ -24,7 +24,7 @@ module Faraday
|
|
24
24
|
# options - Storage options (default: {}).
|
25
25
|
# :logger - A Logger object to be used to emit warnings.
|
26
26
|
# :store - An cache store object that should
|
27
|
-
# respond to '
|
27
|
+
# respond to 'read', 'write', and 'delete'.
|
28
28
|
# :serializer - A serializer object that should
|
29
29
|
# respond to 'dump' and 'load'.
|
30
30
|
def initialize(options = {})
|
@@ -46,6 +46,7 @@ module Faraday
|
|
46
46
|
entry = serialize_entry(request.serializable_hash, response.serializable_hash)
|
47
47
|
|
48
48
|
entries = cache.read(key) || []
|
49
|
+
entries = entries.dup if entries.frozen?
|
49
50
|
|
50
51
|
entries.reject! do |(cached_request, cached_response)|
|
51
52
|
response_matches?(request, deserialize_object(cached_request), deserialize_object(cached_response))
|
data/spec/response_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Faraday::HttpCache::Response do
|
|
22
22
|
expect(response).not_to be_cacheable_in_shared_cache
|
23
23
|
end
|
24
24
|
|
25
|
-
[200, 203, 300, 301, 302, 404, 410].each do |status|
|
25
|
+
[200, 203, 300, 301, 302, 307, 404, 410].each do |status|
|
26
26
|
it "the response is cacheable if the status code is #{status} and the response is fresh" do
|
27
27
|
headers = { 'Cache-Control' => 'max-age=400' }
|
28
28
|
response = Faraday::HttpCache::Response.new(status: status, response_headers: headers)
|
@@ -53,7 +53,7 @@ describe Faraday::HttpCache::Response do
|
|
53
53
|
expect(response).not_to be_cacheable_in_private_cache
|
54
54
|
end
|
55
55
|
|
56
|
-
[200, 203, 300, 301, 302, 404, 410].each do |status|
|
56
|
+
[200, 203, 300, 301, 302, 307, 404, 410].each do |status|
|
57
57
|
it "the response is cacheable if the status code is #{status} and the response is fresh" do
|
58
58
|
headers = { 'Cache-Control' => 'max-age=400' }
|
59
59
|
response = Faraday::HttpCache::Response.new(status: status, response_headers: headers)
|
@@ -130,6 +130,12 @@ describe Faraday::HttpCache::Response do
|
|
130
130
|
response = Faraday::HttpCache::Response.new
|
131
131
|
expect(response.max_age).to be_nil
|
132
132
|
end
|
133
|
+
|
134
|
+
it 'returns nil when falling back to expiration date but it is not RFC 2616 compliant' do
|
135
|
+
headers = { 'Expires' => 'Mon, 1 Jan 2001 00:00:00 GMT' }
|
136
|
+
response = Faraday::HttpCache::Response.new(response_headers: headers)
|
137
|
+
expect(response.max_age).to be_nil
|
138
|
+
end
|
133
139
|
end
|
134
140
|
|
135
141
|
describe 'age calculation' do
|
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.1.
|
4
|
+
version: 1.1.1
|
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-04
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|