Class: IronCache::Caches

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_cache/caches.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Caches

Returns a new instance of Caches.



8
9
10
# File 'lib/iron_cache/caches.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/iron_cache/caches.rb', line 6

def client
  @client
end

Instance Method Details

#clear(options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/iron_cache/caches.rb', line 45

def clear(options={})
  res = @client.post(path(options) + "/clear")
  json = @client.parse_response(res, true)
  #return Message.new(self, res)
  return ResponseBase.new(json)
end

#get(options = {}) ⇒ Object

options:

:name => can specify an alternative queue name


36
37
38
39
40
41
42
43
# File 'lib/iron_cache/caches.rb', line 36

def get(options={})
  if options.is_a?(String)
    options = {:name=>options}
  end
  options[:name] ||= @client.cache_name
  res = @client.parse_response(@client.get(path(options)))
  Cache.new(@client, res)
end

#list(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/iron_cache/caches.rb', line 20

def list(options={})
  ret = []
  res = @client.get("#{path(options)}", options)
  @client.logger.debug res.inspect
  parsed = @client.parse_response(res, true)
  @client.logger.debug parsed.inspect
  parsed.each do |q|
    @client.logger.debug "cache: " + q.inspect
    q = Cache.new(@client, q)
    ret << q
  end
  ret
end

#path(options = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/iron_cache/caches.rb', line 12

def path(options={})
  path = "projects/#{@client.project_id}/caches"
  if options[:name]
    path << "/#{CGI::escape(options[:name]).gsub('+', '%20')}"
  end
  path
end