faraday-manual-cache 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/faraday-manual-cache.gemspec +1 -1
- data/lib/faraday/manual_cache.rb +11 -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: a68b0911c029cdb80405cae43fee9559e976d7bb
|
4
|
+
data.tar.gz: 64f2279973047eb744398526cf3ce5a62f541c0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b54c26beca7332c2bcd52bd5f2c0d504e43187ce3c6f52f8e48f508063155ca4f349f0a2dda20090789afdd6a4ec52ab106afa3076ab466bfd309c21d8776db
|
7
|
+
data.tar.gz: 0a9c7c49bddc69c01d6243f9e1c102bc221ad771a74f288bdf917023481e9daf64491fa154aa5c53dcb3af7655d34e90f6e742330d184b906ff9227ada5e782b
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = 'faraday-manual-cache'
|
4
|
-
spec.version = '0.1.
|
4
|
+
spec.version = '0.1.1'
|
5
5
|
spec.authors = ['Daniel O\'Brien']
|
6
6
|
spec.email = ['dan@dobs.org']
|
7
7
|
spec.summary = %q(A super simple Faraday cache implementation.)
|
data/lib/faraday/manual_cache.rb
CHANGED
@@ -39,20 +39,20 @@ module Faraday
|
|
39
39
|
def call!(env)
|
40
40
|
response_env = cached_response(env)
|
41
41
|
|
42
|
-
if response_env
|
43
|
-
info "Cache HIT: #{key(env)}"
|
42
|
+
if response_env
|
44
43
|
response_env.response_headers['x-faraday-manual-cache'] = 'HIT'
|
45
44
|
to_response(cached_response(env))
|
46
45
|
else
|
47
|
-
info "Cache MISS: #{key(env)}"
|
48
46
|
@app.call(env).on_complete do |response_env|
|
49
47
|
response_env.response_headers['x-faraday-manual-cache'] = 'MISS'
|
50
|
-
cache_response(response_env)
|
48
|
+
cache_response(response_env)
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
def cache_response(env)
|
54
|
+
return unless cacheable?(env) && !env.request_headers['x-faraday-manual-cache']
|
55
|
+
|
56
56
|
info "Cache WRITE: #{key(env)}"
|
57
57
|
@store.write(key(env), env, expires_in: @expires_in)
|
58
58
|
end
|
@@ -62,7 +62,13 @@ module Faraday
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def cached_response(env)
|
65
|
-
@store.fetch(key(env)) if cacheable?(env)
|
65
|
+
response_env = @store.fetch(key(env)) if cacheable?(env) && !env.request_headers['x-faraday-manual-cache']
|
66
|
+
if response_env
|
67
|
+
info "Cache HIT: #{key(env)}"
|
68
|
+
else
|
69
|
+
info "Cache MISS: #{key(env)}"
|
70
|
+
end
|
71
|
+
response_env
|
66
72
|
end
|
67
73
|
|
68
74
|
def info(message)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-manual-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel O'Brien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|