faraday_middleware 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday_middleware/response/caching.rb +16 -7
- data/lib/faraday_middleware/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9533a5d53e299a95e8b2aa19d277ac32ed800930c0abd4d92c67f025c98101d
|
4
|
+
data.tar.gz: 7261d4f25c4e0edeaaba0718947af74439d2fef8a114278a74f8de63f0f6c575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae2e4ea996bb4a2ad2762a7c0812c8734879205adb05eb88aed062f0be24b26fa18de82e6cc33c7c86dfc8f7c4fa8694522732c457643c8a4d3991e50ac095a
|
7
|
+
data.tar.gz: 512f5e9888e8adf5ac0d93c501470028079b463e407697353d55ef603b3a2590f46b9a6530a0a688a54e391fe9033302551f133b6d216281bf01c451e1a73f85
|
@@ -27,14 +27,16 @@ module FaradayMiddleware
|
|
27
27
|
# cache - An object that responds to read and write (default: nil).
|
28
28
|
# options - An options Hash (default: {}):
|
29
29
|
# :ignore_params - String name or Array names of query
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# params that should be ignored when forming
|
31
|
+
# the cache key (default: []).
|
32
32
|
# :write_options - Hash of settings that should be passed as the
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
33
|
+
# third options parameter to the cache's #write
|
34
|
+
# method. If not specified, no options parameter
|
35
|
+
# will be passed.
|
36
36
|
# :full_key - Boolean - use full URL as cache key:
|
37
|
-
#
|
37
|
+
# (url.host + url.request_uri)
|
38
|
+
# :status_codes - Array of http status code to be cache
|
39
|
+
# (default: CACHEABLE_STATUS_CODE)
|
38
40
|
#
|
39
41
|
# Yields if no cache is given. The block should return a cache object.
|
40
42
|
def initialize(app, cache = nil, options = {})
|
@@ -86,6 +88,13 @@ module FaradayMiddleware
|
|
86
88
|
@full_key ||= @options[:full_key]
|
87
89
|
end
|
88
90
|
|
91
|
+
def custom_status_codes
|
92
|
+
@custom_status_codes ||= begin
|
93
|
+
codes = CACHEABLE_STATUS_CODES & Array(@options[:status_codes]).map(&:to_i)
|
94
|
+
codes.any? ? codes : CACHEABLE_STATUS_CODES
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
89
98
|
def cache_on_complete(env)
|
90
99
|
key = cache_key(env)
|
91
100
|
if (cached_response = cache.read(key))
|
@@ -101,7 +110,7 @@ module FaradayMiddleware
|
|
101
110
|
end
|
102
111
|
|
103
112
|
def store_response_in_cache(key, response)
|
104
|
-
return unless
|
113
|
+
return unless custom_status_codes.include?(response.status)
|
105
114
|
|
106
115
|
if @options[:write_options]
|
107
116
|
cache.write(key, response, @options[:write_options])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Michaels-Ober
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|