Skip to content

Commit

Permalink
Make multiple attempts to contact the same origin server when checkin…
Browse files Browse the repository at this point in the history
…g caching
  • Loading branch information
DanielHeath committed Nov 9, 2016
1 parent 6c700ae commit 2209271
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change history / upgrade notes

# 1.2.2

`be_cacheable` now makes requests for the same resource until it gets N requests (default=4) served by the same edge node.

# 1.2.0

## Caching
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
akamai_rspec (1.2.1)
akamai_rspec (1.2.2)
json (>= 1.8)
rest-client (~> 1.8)
rspec (>= 3.2)
Expand Down
2 changes: 1 addition & 1 deletion akamai_rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)

Gem::Specification.new do |s|
s.name = 'akamai_rspec'
s.version = "1.2.1"
s.version = "1.2.2"
s.authors = ['Bianca Gibson', 'Daniel Heath']
s.email = '[email protected]'
s.files = Dir['lib/*']
Expand Down
10 changes: 4 additions & 6 deletions lib/akamai_rspec/matchers/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

module AkamaiRSpec
module Matchers
define :be_cacheable do |request_count: :until_same_server, headers: {}, allow_refresh: false|
define :be_cacheable do |request_count: 4, only_same_server: true, headers: {}, allow_refresh: false|
match do |url|
@responses = []
fail("URL must be a string") unless url.is_a? String

if request_count == :until_same_server
if only_same_server
while response = AkamaiRSpec::Request.get(url, headers) do
if cache_servers.include?(cache_server response.headers[:x_cache])
@responses.push response
break
end
responses_from_same_server = cache_servers.count(cache_server response.headers[:x_cache])
@responses.push response
break if responses_from_same_server >= request_count
end
else
@responses = (1..request_count).map {
Expand Down

0 comments on commit 2209271

Please sign in to comment.