httparty-icebox-delooks 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -165,6 +165,37 @@ module HTTParty #:nodoc:
165
165
  define_method(method_name) { raise NoMethodError, "Please implement method #{method_name} in your store class" }
166
166
  end
167
167
  end
168
+
169
+ # ==== Store objects in memory
170
+ # See HTTParty::Icebox::ClassMethods.cache
171
+ #
172
+ class MemcachierStore < AbstractStore
173
+ def initialize(options={})
174
+ super; @store = {}; self
175
+ end
176
+ def set(key, value)
177
+ Cache.logger.info("Cache: set (#{key})")
178
+ Rails.cache.write(key, [Time.now, value]); true
179
+ end
180
+ def get(key)
181
+ data = Rails.cache.read(key)
182
+ data = data[1] if !data.nil?
183
+ Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
184
+ data
185
+ end
186
+ def exists?(key)
187
+ Rails.cache.exist?(key)
188
+ end
189
+ def stale?(key)
190
+ return true unless exists?(key)
191
+ Time.now - created(key) > @timeout
192
+ end
193
+ private
194
+ def created(key)
195
+ data = Rails.cache.read(key)
196
+ data[0]
197
+ end
198
+ end
168
199
 
169
200
  # ==== Store objects in memory
170
201
  # See HTTParty::Icebox::ClassMethods.cache
@@ -187,8 +218,7 @@ module HTTParty #:nodoc:
187
218
  end
188
219
  def stale?(key)
189
220
  return true unless exists?(key)
190
- #Time.now - created(key) > @timeout
191
- false
221
+ Time.now - created(key) > @timeout
192
222
  end
193
223
  private
194
224
  def created(key)
@@ -1,5 +1,5 @@
1
1
  module Httparty
2
2
  module Icebox
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparty-icebox-delooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-06-14 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &70257156209840 !ruby/object:Gem::Requirement
17
+ requirement: &70243402498660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 0.8.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70257156209840
25
+ version_requirements: *70243402498660
26
26
  description: Cache responses in HTTParty models
27
27
  email:
28
28
  - kristoffer@sachse.nu