faraday-http-cache 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/faraday/http_cache/storage.rb +13 -8
- data/spec/storage_spec.rb +13 -5
- 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: 63e018cc1939d1fefb02b7d90f810a71afdd15b9
|
4
|
+
data.tar.gz: 408cdbabae9f4a6d144b0c799341bf4c7a46adea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5247068c970b755688f710a557a4d6e6366cbb909c303f16a67e1cb1814240e6a709b4b7bba3d75048c31b0c716b36ce34b4b85152455e9d13e299e92be08ead
|
7
|
+
data.tar.gz: bfe06e86bdd004958ac7ca444c346f3fd5060fa8d61e54e66075464c215afb3bca14e7c5ed10714bd78ebc79a77e7aab7bdb2326b1e919e3b442d7980ff5aabe
|
data/README.md
CHANGED
@@ -48,8 +48,10 @@ client = Faraday.new do |builder|
|
|
48
48
|
builder.adapter Faraday.default_adapter
|
49
49
|
end
|
50
50
|
```
|
51
|
-
The default store provided is a simple in memory cache that lives on the client
|
52
|
-
|
51
|
+
The default store provided is a simple in memory cache that lives on the client instance.
|
52
|
+
This type of store **might not be persisted across multiple processes or connection instances**
|
53
|
+
so it is probably not suitable for most production environments.
|
54
|
+
Make sure that you configure a store that is suitable for you.
|
53
55
|
|
54
56
|
the stdlib `JSON` module is used for serialization by default.
|
55
57
|
If you expect to be dealing with images, you can use [Marshal][marshal] instead, or
|
@@ -6,10 +6,11 @@ module Faraday
|
|
6
6
|
# Internal: A wrapper around an ActiveSupport::CacheStore to store responses.
|
7
7
|
#
|
8
8
|
# Examples
|
9
|
+
#
|
9
10
|
# # Creates a new Storage using a MemCached backend from ActiveSupport.
|
10
11
|
# Faraday::HttpCache::Storage.new(:mem_cache_store)
|
11
12
|
#
|
12
|
-
# # Reuse some other instance of
|
13
|
+
# # Reuse some other instance of an ActiveSupport::Cache::Store object.
|
13
14
|
# Faraday::HttpCache::Storage.new(Rails.cache)
|
14
15
|
#
|
15
16
|
# # Creates a new Storage using Marshal for serialization.
|
@@ -76,17 +77,21 @@ module Faraday
|
|
76
77
|
private
|
77
78
|
|
78
79
|
# Internal: Generates a String key for a given request object.
|
79
|
-
# The request object is folded into a sorted Array (since we can't count
|
80
|
-
# on hashes order on Ruby 1.8), encoded as JSON and digested as a `SHA1`
|
81
|
-
# string.
|
82
80
|
#
|
83
|
-
# Returns the
|
81
|
+
# Returns the digested String.
|
84
82
|
def cache_key_for(request)
|
85
|
-
|
86
|
-
|
83
|
+
digest = Digest::SHA1.new
|
84
|
+
digest.update 'method'
|
85
|
+
digest.update request[:method].to_s
|
86
|
+
digest.update 'request_headers'
|
87
|
+
request[:request_headers].keys.sort.each do |key|
|
88
|
+
digest.update key.to_s
|
89
|
+
digest.update request[:request_headers][key].to_s
|
87
90
|
end
|
91
|
+
digest.update 'url'
|
92
|
+
digest.update request[:url].to_s
|
88
93
|
|
89
|
-
|
94
|
+
digest.to_s
|
90
95
|
end
|
91
96
|
|
92
97
|
# Internal: Creates a cache store from 'ActiveSupport' with a set of options.
|
data/spec/storage_spec.rb
CHANGED
@@ -49,7 +49,7 @@ describe Faraday::HttpCache::Storage do
|
|
49
49
|
|
50
50
|
context 'with default serializer' do
|
51
51
|
let(:serialized) { JSON.dump(response.serializable_hash) }
|
52
|
-
let(:cache_key) { '
|
52
|
+
let(:cache_key) { '084dd517af7651a9ca7823728544b9b55e0cc130' }
|
53
53
|
it_behaves_like 'serialization'
|
54
54
|
|
55
55
|
context 'with ASCII character in response that cannot be converted to UTF-8' do
|
@@ -73,11 +73,19 @@ describe Faraday::HttpCache::Storage do
|
|
73
73
|
context 'with Marshal serializer' do
|
74
74
|
let(:storage) { Faraday::HttpCache::Storage.new store: cache, serializer: Marshal }
|
75
75
|
let(:serialized) { Marshal.dump(response.serializable_hash) }
|
76
|
-
let(:cache_key)
|
77
|
-
|
78
|
-
Digest::SHA1.hexdigest(Marshal.dump(array))
|
79
|
-
end
|
76
|
+
let(:cache_key) { '084dd517af7651a9ca7823728544b9b55e0cc130' }
|
77
|
+
|
80
78
|
it_behaves_like 'serialization'
|
79
|
+
|
80
|
+
it 'should have a unique cache key' do
|
81
|
+
request = { method: :get, request_headers: {}, url: URI.parse('http://foo.bar/path/to/somewhere') }
|
82
|
+
duplicate_request = { method: :get, request_headers: {}, url: URI.parse('http://foo.bar/path/to/somewhere') }
|
83
|
+
storage = Faraday::HttpCache::Storage.new(serializer: Marshal)
|
84
|
+
response = Faraday::HttpCache::Response.new(status: 200, body: 'body')
|
85
|
+
storage.write(request, response)
|
86
|
+
read_response = storage.read(duplicate_request).serializable_hash
|
87
|
+
expect(read_response).to eq(response.serializable_hash)
|
88
|
+
end
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
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: 0.4.
|
4
|
+
version: 0.4.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: 2014-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|