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 +4 -0
- data/lib/httparty-icebox.rb +29 -7
- data/lib/httparty-icebox/version.rb +1 -1
- metadata +3 -5
data/History
CHANGED
data/lib/httparty-icebox.rb
CHANGED
@@ -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
|
-
|
72
|
-
|
73
|
-
|
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
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
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.
|
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-
|
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.
|
69
|
+
rubygems_version: 1.8.4
|
72
70
|
signing_key:
|
73
71
|
specification_version: 3
|
74
72
|
summary: Caching for HTTParty
|