Class: Rack::Cache::MetaStore::Heap

Inherits:
Rack::Cache::MetaStore show all
Defined in:
lib/rack/cache/meta_store.rb

Overview

Concrete MetaStore implementation that uses a simple Hash to store request/response pairs on the heap.

Constant Summary

Constants inherited from Rack::Cache::MetaStore

DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rack::Cache::MetaStore

#cache_key, #invalidate, #lookup, #store

Constructor Details

#initialize(hash = {}, options = {}) ⇒ Heap

Returns a new instance of Heap.



200
201
202
203
# File 'lib/rack/cache/meta_store.rb', line 200

def initialize(hash={}, options = {})
  @hash = hash
  @options = options
end

Class Method Details

.resolve(uri, options = {}) ⇒ Object



226
227
228
# File 'lib/rack/cache/meta_store.rb', line 226

def self.resolve(uri, options = {})
  new({}, options)
end

Instance Method Details

#purge(key) ⇒ Object



217
218
219
220
# File 'lib/rack/cache/meta_store.rb', line 217

def purge(key)
  @hash.delete(key)
  nil
end

#read(key) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/rack/cache/meta_store.rb', line 205

def read(key)
  if data = @hash[key]
    Marshal.load(data)
  else
    []
  end
end

#to_hashObject



222
223
224
# File 'lib/rack/cache/meta_store.rb', line 222

def to_hash
  @hash
end

#write(key, entries, ttl = nil) ⇒ Object



213
214
215
# File 'lib/rack/cache/meta_store.rb', line 213

def write(key, entries, ttl = nil)
  @hash[key] = Marshal.dump(entries)
end