httparty-icebox 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.2
2
+ * minor enhancements
3
+ * Return a cached result if network fails. [Andreas Garnæs]
4
+
1
5
  == 0.0.1
2
6
 
3
7
  * major enhancements
@@ -68,9 +68,19 @@ module HTTParty #:nodoc:
68
68
  return cache.get(key)
69
69
  else
70
70
  Cache.logger.debug "/!\\ NETWORK -- GET #{path}#{options[:query]}"
71
- response = get_without_caching(path, options)
72
- cache.set(key, response) if response.code.to_s == "200" # this works for string and integer response codes
73
- return response
71
+
72
+ begin
73
+ response = get_without_caching(path, options)
74
+ cache.set(key, response) if response.code.to_s == "200" # this works for string and integer response codes
75
+ return response
76
+ rescue
77
+ if cache.exists?(key)
78
+ Cache.logger.debug "!!! NETWORK FAILED -- RETURNING STALE CACHE"
79
+ return cache.get(key, true)
80
+ else
81
+ raise
82
+ end
83
+ end
74
84
  end
75
85
  end
76
86
 
@@ -95,10 +105,22 @@ module HTTParty #:nodoc:
95
105
  @store = self.class.lookup_store(store).new(options)
96
106
  end
97
107
 
98
- def get(key); @store.get encode(key) unless stale?(key); end
99
- def set(key, value);puts "Cache.set, key: #{key}, value: #{value}"; @store.set encode(key), value; end
100
- def exists?(key); @store.exists? encode(key); end
101
- def stale?(key); @store.stale? encode(key); end
108
+ def get(key, force=false)
109
+ @store.get encode(key) if !stale?(key) || force
110
+ end
111
+
112
+ def set(key, value)
113
+ puts "Cache.set, key: #{key}, value: #{value}"
114
+ @store.set encode(key), value
115
+ end
116
+
117
+ def exists?(key)
118
+ @store.exists? encode(key)
119
+ end
120
+
121
+ def stale?(key)
122
+ @store.stale? encode(key)
123
+ end
102
124
 
103
125
  def self.logger; @logger || default_logger; end
104
126
  def self.default_logger; logger = ::Logger.new(STDERR); end
@@ -1,5 +1,5 @@
1
1
  module Httparty
2
2
  module Icebox
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: httparty-icebox
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kristoffer Sachse
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-15 00:00:00 +01:00
15
- default_executable:
14
+ date: 2011-06-08 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: httparty
@@ -44,7 +43,6 @@ files:
44
43
  - httparty-icebox.gemspec
45
44
  - lib/httparty-icebox.rb
46
45
  - lib/httparty-icebox/version.rb
47
- has_rdoc: true
48
46
  homepage: https://github.com/sachse/httparty-icebox
49
47
  licenses: []
50
48
 
@@ -68,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
66
  requirements: []
69
67
 
70
68
  rubyforge_project: httparty-icebox
71
- rubygems_version: 1.6.2
69
+ rubygems_version: 1.8.4
72
70
  signing_key:
73
71
  specification_version: 3
74
72
  summary: Caching for HTTParty