Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Update README.md with more usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Feb 21, 2018
1 parent 7bae990 commit 66abe49
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,29 @@ url = 'https://status.rubygems.org'
request = {'Version' => 'HTTP/1.1'}
cached = {}

# test without cached response
CacheRules.validate url, request, cached

=> {:body=>nil, :code=>307, :headers=>{"Cache-Lookup"=>"MISS", "Location"=>"https://status.rubygems.org"}}
=> {:body=>nil, :code=>307, :headers=>{"Cache-Lookup"=>"MISS", "Location"=>"https://status.rubygems.org"}}

cached = { "Date" => {"timestamp"=>1420095825}, "X-Cache-Req-Date" => {"timestamp"=>1420268625}, "X-Cache-Res-Date" => {"timestamp"=>1420268625} }

# test with cached response (status code 200 because no ETag or If-None-Match supplied)
CacheRules.validate url, request, cached

=> {:body=>"stale", :code=>200, :headers=>{"Date"=>"Wed, 21 Feb 2018 05:09:27 GMT", "Age"=>"99094242", "Warning"=>"110 - \"Response is Stale\"", "Cache-Lookup"=>"STALE"}}

request = {"Version"=>"HTTP/1.1", "If-None-Match"=>"*"}
cached = { "Date" => {"timestamp"=>1519190160}, "X-Cache-Req-Date" => {"timestamp"=>1519190160}, "X-Cache-Res-Date" => {"timestamp"=>1519190160} }

# test with cached response (status code 304 because If-None-Match supplied)
=> {:body=>nil, :code=>304, :headers=>{"Date"=>"Wed, 21 Feb 2018 05:15:01 GMT", "Age"=>"241", "Warning"=>"110 - \"Response is Stale\"", "Cache-Lookup"=>"STALE"}}
```

The `request` headers must be a Ruby Hash or Array of 2-element Arrays.
The `cached` headers must already have been normalized by this caching library.
The `cached` headers must already have been normalized by this caching library, i.e: they **must** include the `Date['timestamp'], X-Cache-Req-Date['timestamp'], X-Cache-Res-Date['timestamp']` array keys.

See `test/` directory for more examples.

## Decision tables

Expand Down

0 comments on commit 66abe49

Please sign in to comment.