cacheability 1.1.0 → 1.2.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.
data/README CHANGED
@@ -1,16 +1,19 @@
1
- Cacheability
2
- ============
1
+ = cacheability
2
+
3
3
  A gem that makes client-side caching of HTTP requests a no-brainer. It is built upon the Rack:Cache gem from Ryan Tomayko.
4
4
 
5
5
  Cached data can be stored in heap, file or memcached. See the Rack::Cache documentation (http://tomayko.com/src/rack-cache/) for more information.
6
6
 
7
- Installation
8
- ============
9
- gem install cryx-cacheability
7
+ = Installation
8
+
9
+ gem install cacheability
10
10
 
11
- Usage
12
- =====
11
+ = Usage
12
+
13
13
  require 'cacheability/restclient'
14
+
15
+ RestClient.log = 'stdout' # displays requests and status codes
16
+
14
17
  resource = RestClient::CacheableResource.new( 'http://some/cacheable/resource',
15
18
  :cache => { :metastore => 'file:/tmp/cache/meta',
16
19
  :entitystore => 'file:/tmp/cache/body' }
@@ -27,15 +30,14 @@ Do yourself a favor and read:
27
30
  * Things Caches Do - http://tomayko.com/writings/things-caches-do
28
31
 
29
32
 
30
- Supported libraries
31
- ===================
33
+ = Supported libraries
34
+
32
35
  * rest-client > 0.9
33
36
 
34
- Dependencies
35
- ============
37
+ = Dependencies
38
+
36
39
  * rack-cache
37
40
 
38
- COPYRIGHT
39
- =========
41
+ = COPYRIGHT
40
42
 
41
43
  Copyright (c) 2008 Cyril Rohr. See LICENSE for details.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 1
3
- :minor: 1
4
2
  :patch: 0
3
+ :major: 1
4
+ :minor: 2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cacheability}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril Rohr"]
@@ -37,7 +37,8 @@ Gem::Specification.new do |s|
37
37
  s.summary = %q{A gem that makes client-side caching of HTTP requests a no-brainer. Replace your calls to RestClient::Resource.new with RestClient::CacheableResource.new and the caching is taken care of for you ! Supports heap, file and memcache storage.}
38
38
  s.test_files = [
39
39
  "spec/cacheability_spec.rb",
40
- "spec/spec_helper.rb"
40
+ "spec/spec_helper.rb",
41
+ "spec/test.rb"
41
42
  ]
42
43
 
43
44
  if s.respond_to? :specification_version then
@@ -24,7 +24,7 @@ module RestClient
24
24
 
25
25
  class CacheableResource < Resource
26
26
  attr_reader :cache
27
- CACHE_DEFAULT_OPTIONS = {:verbose => true}.freeze
27
+ CACHE_DEFAULT_OPTIONS = {:verbose => false}
28
28
 
29
29
  def initialize(*args)
30
30
  super(*args)
@@ -52,12 +52,13 @@ module RestClient
52
52
  "rack.multiprocess" => true,
53
53
  "rack.url_scheme" => uri.scheme,
54
54
  "rack.input" => StringIO.new,
55
- "rack.errors" => StringIO.new # Rack-Cache writes errors into this field
55
+ "rack.errors" => logger # Rack-Cache writes errors into this field
56
56
  }
57
57
  debeautify_headers(additional_headers).each do |key, value|
58
58
  env.merge!("HTTP_"+key.to_s.gsub("-", "_").upcase => value)
59
59
  end
60
60
  response = MockHTTPResponse.new(cache.call(env))
61
+ env['rack.errors'].close if env['rack.errors'].respond_to?(:close)
61
62
  RestClient::Response.new(response.body, response)
62
63
  else
63
64
  super(additional_headers)
@@ -88,5 +89,17 @@ module RestClient
88
89
  response = RestClient::Response.new("", e.response)
89
90
  [304, debeautify_headers( response.headers ), [response.to_s]]
90
91
  end
92
+
93
+ # Ugly, but waiting for RestClient to become smarter
94
+ #
95
+ def logger
96
+ return StringIO.new unless log_to = RestClient.log
97
+ case log_to
98
+ when 'stdout' then STDOUT
99
+ when 'stderr' then STDERR
100
+ else
101
+ File.new(log_to, 'a')
102
+ end
103
+ end
91
104
  end
92
105
  end
@@ -7,6 +7,7 @@ describe RestClient::CacheableResource do
7
7
  require File.dirname(__FILE__) + '/../lib/cacheability/restclient'
8
8
  before do
9
9
  @cache_options = {:metastore => 'file:/tmp/cache/meta', :entitystore => 'file:/tmp/cache/body'}
10
+ RestClient.log = nil
10
11
  end
11
12
 
12
13
  it "should instantiate the cache at init" do
@@ -60,7 +61,7 @@ describe RestClient::CacheableResource do
60
61
  it "should render a RestClient::Response even when the data is coming from the cache" do
61
62
  @resource.cache.should_receive(:call).and_return([200, {'ADDITIONAL_HEADER' => 'whatever'}, "body"])
62
63
  response = @resource.get({'HTTP_ADDITIONAL_HEADER' => 'whatever'}, true)
63
- response.should be_is_a(RestClient::Response)
64
+ response.should be_a(RestClient::Response)
64
65
  response.code.should == 200
65
66
  response.headers.should == {:ADDITIONAL_HEADER => 'whatever'}
66
67
  response.to_s.should == "body"
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+ require File.dirname(__FILE__) + '/../lib/cacheability/restclient'
4
+ require 'pp'
5
+ RestClient.log = 'stdout'
6
+
7
+ RestClient::CacheableResource.new('https://api.grid5000.fr/sid/versions/current.json', :user => 'crohr', :password => 'pmtppe1m', :cache => {:verbose => false}).get
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheability
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
@@ -73,3 +73,4 @@ summary: A gem that makes client-side caching of HTTP requests a no-brainer. Rep
73
73
  test_files:
74
74
  - spec/cacheability_spec.rb
75
75
  - spec/spec_helper.rb
76
+ - spec/test.rb