faraday-http-cache 1.2.2 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a62aee8278ee280538fcda4370c230496f9aa26
4
- data.tar.gz: ed354b7f472d84e17c996d2a97c61da81f41bc92
3
+ metadata.gz: 591c5305967c1a77f52be280ad1c2b31f8b6c1d5
4
+ data.tar.gz: b7a40463bdffe22b23ad0a602b225f1df3041bd8
5
5
  SHA512:
6
- metadata.gz: fe2d52575496d9f73201deff62c664611c664148a2bde2f01adc1d63074c35ff6dda1103d19171dcb1f114fc1eb563d4235abc7e2439a5d8a6cf0ab88d761a8a
7
- data.tar.gz: a7c46d882287552df02f7f3f3baf25c9182ac16c47905bef51520e41895d1baebc81f10ea33798d93c51df85593f16c6829fa7169a71df41c12940f81351986c
6
+ metadata.gz: 20567be380e251d4c16d9b3ba1a3f15feca47c1d3f2130f2f262c0e42c07180bd92179c71ae812dbedf44c779af4ade72c7a1fdaaccab706b876e917d4e477b5
7
+ data.tar.gz: 1d2c5ab40e991aa6acd2862d40f2fb44ca0741c4f0c708f7751805340bc941cbeda505d07be1d021b8375381fc952e9fbcbe4f507ad9719cfa311d5b7337139e
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Faraday Http Cache
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/plataformatec/faraday-http-cache.png?branch=master)](https://travis-ci.org/plataformatec/faraday-http-cache)
3
+ [![Build Status](https://secure.travis-ci.org/plataformatec/faraday-http-cache.svg?branch=master)](https://travis-ci.org/plataformatec/faraday-http-cache)
4
4
 
5
5
  a [Faraday](https://github.com/lostisland/faraday) middleware that respects HTTP cache,
6
6
  by checking expiration and validation of the stored responses.
@@ -30,7 +30,7 @@ end
30
30
  ```
31
31
 
32
32
  The middleware accepts a `store` option for the cache backend responsible for recording
33
- the API responses that should be stored. Stores should respond to `write` and `read`,
33
+ the API responses that should be stored. Stores should respond to `write`, `read` and `delete`,
34
34
  just like an object from the `ActiveSupport::Cache` API.
35
35
 
36
36
  ```ruby
@@ -49,7 +49,7 @@ module Faraday
49
49
  #
50
50
  # Returns true if the response is fresh, otherwise false.
51
51
  def fresh?
52
- ttl && ttl > 0
52
+ !cache_control.no_cache? && ttl && ttl > 0
53
53
  end
54
54
 
55
55
  # Internal: Checks if the Response returned a 'Not Modified' status.
@@ -190,6 +190,14 @@ describe Faraday::HttpCache do
190
190
  end
191
191
  end
192
192
 
193
+ context 'when the response has a "no-cache" directive' do
194
+ it 'always revalidate the cached response' do
195
+ client.get('no_cache')
196
+ expect(client.get('no_cache').body).to eq('2')
197
+ expect(client.get('no_cache').body).to eq('3')
198
+ end
199
+ end
200
+
193
201
  it 'logs that a GET response is stored' do
194
202
  expect(logger).to receive(:debug) { |&block| expect(block.call).to eq('HTTP Cache: [GET /get] miss, store') }
195
203
  client.get('get')
@@ -72,13 +72,21 @@ describe Faraday::HttpCache::Response do
72
72
  expect(response).to be_fresh
73
73
  end
74
74
 
75
- it 'is not fresh when the ttl has expired' do
75
+ it 'is not fresh if the ttl has expired' do
76
76
  date = (Time.now - 500).httpdate
77
77
  headers = { 'Cache-Control' => 'max-age=400', 'Date' => date }
78
78
  response = Faraday::HttpCache::Response.new(response_headers: headers)
79
79
 
80
80
  expect(response).not_to be_fresh
81
81
  end
82
+
83
+ it 'is not fresh if Cache Control has "no-cache"' do
84
+ date = (Time.now - 200).httpdate
85
+ headers = { 'Cache-Control' => 'max-age=400, no-cache', 'Date' => date }
86
+ response = Faraday::HttpCache::Response.new(response_headers: headers)
87
+
88
+ expect(response).not_to be_fresh
89
+ end
82
90
  end
83
91
 
84
92
  it 'sets the "Date" header if is not present' do
@@ -109,6 +109,10 @@ class TestApp < Sinatra::Base
109
109
  end
110
110
  end
111
111
 
112
+ get '/no_cache' do
113
+ [200, { 'Cache-Control' => 'max-age=200, no-cache', 'ETag' => settings.counter.to_s }, increment_counter]
114
+ end
115
+
112
116
  get '/vary' do
113
117
  [200, { 'Cache-Control' => 'max-age=50', 'Vary' => 'User-Agent' }, increment_counter]
114
118
  end
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.2.2
4
+ version: 1.3.0
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-08-27 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  requirements: []
74
74
  rubyforge_project:
75
- rubygems_version: 2.4.5
75
+ rubygems_version: 2.5.1
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: A Faraday middleware that stores and validates cache expiration.