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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9908ab5ca8956f133b3371bb8313fc70eefa01e9
4
- data.tar.gz: 71e6b04c0c4bd4f512acab094c09cc4c68f60c41
3
+ metadata.gz: a68b0911c029cdb80405cae43fee9559e976d7bb
4
+ data.tar.gz: 64f2279973047eb744398526cf3ce5a62f541c0f
5
5
  SHA512:
6
- metadata.gz: c46b3edf75261d00b1c039fa77f03c247b4cbec6acc21421b6a574f308c034937072347d52d9cbbc5f7f234b96d6a5f73d41f89364dbaedef825ff4e50891b4e
7
- data.tar.gz: 254fa5f85405e188bcc66f97275fd0dcd086f418275a79c61c95133c4757b4318342f9b073a9cc211180968c5f90d1f145f3d553def7fa4bc5a1648afe28f6c7
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.0'
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.)
@@ -39,20 +39,20 @@ module Faraday
39
39
  def call!(env)
40
40
  response_env = cached_response(env)
41
41
 
42
- if response_env && !env.request_headers['x-faraday-manual-cache']
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) if cacheable?(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.0
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-23 00:00:00.000000000 Z
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport