cryx-cacheability 0.1.2 → 1.0.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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Cyril Rohr
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,41 @@
1
+ Cacheability
2
+ ============
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
+
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
+
7
+ Installation
8
+ ============
9
+ gem install cryx-cacheability
10
+
11
+ Usage
12
+ =====
13
+ require 'cacheability/restclient'
14
+ resource = RestClient::CacheableResource.new( 'http://some/cacheable/resource',
15
+ :cache => { :metastore => 'file:/tmp/cache/meta',
16
+ :entitystore => 'file:/tmp/cache/body' }
17
+ )
18
+ resource.get # get from remote server, and cache if possible
19
+ # ...
20
+ resource.get # get from cache, if still fresh.
21
+ # ...
22
+ resource.get(:cache_control => 'no-cache') # explicitly tells to bypass the cache, requires rack-cache >= 0.4
23
+ # ...
24
+
25
+ Do yourself a favor and read:
26
+ * the HTTP specification related to HTTP caching - http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
27
+ * Things Caches Do - http://tomayko.com/writings/things-caches-do
28
+
29
+
30
+ Supported libraries
31
+ ===================
32
+ * rest-client > 0.9
33
+
34
+ Dependencies
35
+ ============
36
+ * rack-cache
37
+
38
+ COPYRIGHT
39
+ =========
40
+
41
+ Copyright (c) 2008 Cyril Rohr. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "cacheability"
7
+ s.summary = %Q{TODO}
8
+ s.email = "cyril.rohr@irisa.fr"
9
+ s.homepage = "http://github.com/cryx/cacheability"
10
+ s.description = "A gem that makes client-side caching of HTTP requests a no-brainer. It is built upon the Rack:Cache gem from Ryan Tomayko."
11
+ s.authors = ["Cyril Rohr"]
12
+ s.add_dependency "rack-cache"
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ require 'rake/rdoctask'
19
+ Rake::RDocTask.new do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'cacheability'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README*')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |t|
29
+ t.libs << 'lib' << 'spec'
30
+ t.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |t|
34
+ t.libs << 'lib' << 'spec'
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+ t.rcov = true
37
+ end
38
+
39
+ begin
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features)
42
+ rescue LoadError
43
+ puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
+ end
45
+
46
+ task :default => :spec
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 2
4
- :major: 0
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 0
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cacheability}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cyril Rohr"]
12
+ s.date = %q{2009-08-07}
13
+ s.description = %q{A gem that makes client-side caching of HTTP requests a no-brainer. It is built upon the Rack:Cache gem from Ryan Tomayko.}
14
+ s.email = %q{cyril.rohr@irisa.fr}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION.yml",
25
+ "cacheability.gemspec",
26
+ "lib/cacheability.rb",
27
+ "lib/cacheability/restclient.rb",
28
+ "spec/cacheability_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.has_rdoc = true
32
+ s.homepage = %q{http://github.com/cryx/cacheability}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.2}
36
+ s.summary = %q{TODO}
37
+ s.test_files = [
38
+ "spec/cacheability_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<rack-cache>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rack-cache>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rack-cache>, [">= 0"])
53
+ end
54
+ end
@@ -14,13 +14,17 @@ module RestClient
14
14
  end
15
15
 
16
16
  def to_hash
17
- @headers
17
+ @headers.inject({}) {|out, (key, value)|
18
+ # In Net::HTTP, headers values are arrays
19
+ out[key] = value.split(", ")
20
+ out
21
+ }
18
22
  end
19
23
  end
20
24
 
21
25
  class CacheableResource < Resource
22
26
  attr_reader :cache
23
- CACHE_DEFAULT_OPTIONS = {}.freeze
27
+ CACHE_DEFAULT_OPTIONS = {:verbose => true}.freeze
24
28
 
25
29
  def initialize(*args)
26
30
  super(*args)
@@ -80,7 +84,9 @@ module RestClient
80
84
  response.headers.delete(:x_content_digest) # don't know why, but it seems to make the validation fail if kept...
81
85
  [response.code, debeautify_headers( response.headers ), [response.to_s]]
82
86
  rescue RestClient::NotModified => e
83
- [304, e.response.to_hash, [""]]
87
+ # e is a Net::HTTPResponse
88
+ response = RestClient::Response.new("", e.response)
89
+ [304, debeautify_headers( response.headers ), [response.to_s]]
84
90
  end
85
91
  end
86
92
  end
@@ -21,7 +21,7 @@ describe RestClient::CacheableResource do
21
21
  before do
22
22
  @mock_cache = mock('rack-cache singleton')
23
23
  @mock_rack_errors = mock('string io')
24
- @mock_304_net_http_response = mock('http response', :code => 304, :body => "", :to_hash => {'header1' => 'value1'})
24
+ @mock_304_net_http_response = mock('http response', :code => 304, :body => "", :to_hash => {'header1' => ['value1', 'value2']})
25
25
  Rack::Cache.stub!(:new).and_return(@mock_cache)
26
26
  @env = {
27
27
  'REQUEST_METHOD' => 'GET',
@@ -48,13 +48,13 @@ describe RestClient::CacheableResource do
48
48
  it "should call the backend (bypassing the cache) if the requested resource is not in the cache" do
49
49
  @resource.should_receive(:get).with({'ADDITIONAL-HEADER' => 'whatever'}, false).and_return(mock('rest-client response', :headers => {}, :code => 200, :to_s => 'body'))
50
50
  response = @resource.call(@env.merge({'HTTP_ADDITIONAL_HEADER' => 'whatever'}))
51
- response.should == [200, {}, "body"]
51
+ response.should == [200, {}, ["body"]]
52
52
  end
53
53
 
54
54
  it "should return a 304 not modified response if the call to the backend returned a 304 not modified response" do
55
55
  @resource.should_receive(:get).with({'ADDITIONAL-HEADER' => 'whatever'}, false).and_raise(RestClient::NotModified.new(@mock_304_net_http_response))
56
56
  response = @resource.call(@env.merge({'HTTP_ADDITIONAL_HEADER' => 'whatever'}))
57
- response.should == [304, {"header1"=>"value1"}, ""]
57
+ response.should == [304, {"header1"=>"value1"}, [""]]
58
58
  end
59
59
 
60
60
  it "should render a RestClient::Response even when the data is coming from the cache" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryx-cacheability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-31 00:00:00 -07:00
12
+ date: 2009-08-07 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,20 +28,25 @@ executables: []
28
28
 
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files: []
32
-
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
33
34
  files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
34
39
  - VERSION.yml
35
- - lib/cacheability
36
- - lib/cacheability/restclient.rb
40
+ - cacheability.gemspec
37
41
  - lib/cacheability.rb
42
+ - lib/cacheability/restclient.rb
38
43
  - spec/cacheability_spec.rb
39
44
  - spec/spec_helper.rb
40
45
  has_rdoc: true
41
46
  homepage: http://github.com/cryx/cacheability
47
+ licenses:
42
48
  post_install_message:
43
49
  rdoc_options:
44
- - --inline-source
45
50
  - --charset=UTF-8
46
51
  require_paths:
47
52
  - lib
@@ -60,9 +65,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
65
  requirements: []
61
66
 
62
67
  rubyforge_project:
63
- rubygems_version: 1.2.0
68
+ rubygems_version: 1.3.5
64
69
  signing_key:
65
- specification_version: 2
70
+ specification_version: 3
66
71
  summary: TODO
67
- test_files: []
68
-
72
+ test_files:
73
+ - spec/cacheability_spec.rb
74
+ - spec/spec_helper.rb