Class: IronCache::Items
- Inherits:
-
Object
- Object
- IronCache::Items
- Defined in:
- lib/iron_cache/items.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #delete(key, options = {}) ⇒ Object
-
#get(key, options = {}) ⇒ Object
options: :queue_name => can specify an alternative queue name :timeout => amount of time before message goes back on the queue.
-
#increment(key, amount = 1, options = {}) ⇒ Object
options: :cache_name => can specify an alternative queue name.
-
#initialize(client) ⇒ Items
constructor
A new instance of Items.
- #path(key, options = {}) ⇒ Object
-
#put(key, value, options = {}) ⇒ Object
options: :cache_name => can specify an alternative queue name :expires_in => After this delay in seconds, message will be automatically removed from the cache.
- #url(key, options = {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Items
Returns a new instance of Items.
8 9 10 |
# File 'lib/iron_cache/items.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/iron_cache/items.rb', line 6 def client @client end |
Instance Method Details
#delete(key, options = {}) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/iron_cache/items.rb', line 61 def delete(key, ={}) path2 = "#{self.path(key, )}" res = @client.delete(path2) json = @client.parse_response(res, true) #return Message.new(self, res) return ResponseBase.new(json) end |
#get(key, options = {}) ⇒ Object
options:
:queue_name => can specify an alternative queue name
:timeout => amount of time before message goes back on the queue
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/iron_cache/items.rb', line 19 def get(key, ={}) begin res = @client.get(path(key, ), ) @client.logger.debug "GET response: " + res.inspect json = @client.parse_response(res, true) return Item.new(self, json) rescue Rest::HttpError => ex @client.logger.debug ex.inspect if ex.code == 404 return nil end raise ex end end |
#increment(key, amount = 1, options = {}) ⇒ Object
options:
:cache_name => can specify an alternative queue name
52 53 54 55 56 57 58 59 |
# File 'lib/iron_cache/items.rb', line 52 def increment(key, amount=1, ={}) = .merge(:increment => true) res = @client.post(path(key, ), {:amount => amount}) hash = @client.parse_response(res, true) @client.logger.debug "increment response: " + hash.inspect hash["key"] ||= key return Item.new(self, hash) end |
#path(key, options = {}) ⇒ Object
12 13 14 |
# File 'lib/iron_cache/items.rb', line 12 def path(key, ={}) path = "projects/#{@client.project_id}/caches/#{CGI::escape([:cache_name] || @client.cache_name)}/items/#{CGI::escape(key)}#{'/increment' if [:increment] == true}" end |
#put(key, value, options = {}) ⇒ Object
options:
:cache_name => can specify an alternative queue name
:expires_in => After this delay in seconds, message will be automatically removed from the cache.
41 42 43 44 45 46 47 48 |
# File 'lib/iron_cache/items.rb', line 41 def put(key, value, ={}) to_send = to_send[:body] = value res = @client.put(path(key, ), to_send) json = @client.parse_response(res, true) #return Message.new(self, res) return ResponseBase.new(json) end |
#url(key, options = {}) ⇒ Object
34 35 36 |
# File 'lib/iron_cache/items.rb', line 34 def url(key, ={}) @client.url(path(key, )) end |