Class: IronCache::Cache

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

Instance Method Summary collapse

Constructor Details

#initialize(client, res) ⇒ Cache

Returns a new instance of Cache.



57
58
59
60
# File 'lib/iron_cache/caches.rb', line 57

def initialize(client, res)
  @client = client
  @data = res
end

Instance Method Details

#[](key) ⇒ Object



66
67
68
# File 'lib/iron_cache/caches.rb', line 66

def [](key)
  raw[key]
end

#clear(options = {}) ⇒ Object



118
119
120
# File 'lib/iron_cache/caches.rb', line 118

def clear(options={})
  @client.caches.clear(options.merge(:name=>name))
end

#delete(k, options = {}) ⇒ Object



110
111
112
# File 'lib/iron_cache/caches.rb', line 110

def delete(k, options={})
  @client.items.delete(k, options.merge(:cache_name=>name))
end

#get(k, options = {}) ⇒ Object



101
102
103
# File 'lib/iron_cache/caches.rb', line 101

def get(k, options={})
  @client.items.get(k, options.merge(:cache_name=>name))
end

#idObject



70
71
72
# File 'lib/iron_cache/caches.rb', line 70

def id
  raw["id"]
end

#increment(k, amount = 1, options = {}) ⇒ Object



114
115
116
# File 'lib/iron_cache/caches.rb', line 114

def increment(k, amount=1, options={})
  @client.items.increment(k, amount, options.merge(:cache_name=>name))
end

#load_cacheObject

Used if lazy loading



79
80
81
82
83
84
# File 'lib/iron_cache/caches.rb', line 79

def load_cache
  q = @client.caches.get(:name=>name)
  @client.logger.debug "GOT Q: " + q.inspect
  @data = q.raw
  q
end

#nameObject



74
75
76
# File 'lib/iron_cache/caches.rb', line 74

def name
  raw["name"]
end

#put(k, v, options = {}) ⇒ Object



97
98
99
# File 'lib/iron_cache/caches.rb', line 97

def put(k, v, options={})
  @client.items.put(k, v, options.merge(:cache_name=>name))
end

#rawObject



62
63
64
# File 'lib/iron_cache/caches.rb', line 62

def raw
  @data
end

#reloadObject



86
87
88
# File 'lib/iron_cache/caches.rb', line 86

def reload
  load_cache
end

#sizeObject



90
91
92
93
94
95
# File 'lib/iron_cache/caches.rb', line 90

def size
  return raw["size"] if raw["size"]
  return @size if @size
  q = load_cache()
  @size = q.size
end

#url(k, options = {}) ⇒ Object

Returns the url to this item. It does not actually get the item



106
107
108
# File 'lib/iron_cache/caches.rb', line 106

def url(k, options={})
  @client.items.url(k, options.merge(:cache_name=>name))
end