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

Inherits:
Rack::Cache::MetaStore show all
Defined in:
lib/rack/cache/metastore.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, HEAP, MEM, MEMCACHE, MEMCACHED

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rack::Cache::MetaStore

#lookup, #store

Constructor Details

#initialize(hash = {}) ⇒ Heap

Returns a new instance of Heap.



137
138
139
# File 'lib/rack/cache/metastore.rb', line 137

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

Class Method Details

.resolve(uri) ⇒ Object



160
161
162
# File 'lib/rack/cache/metastore.rb', line 160

def self.resolve(uri)
  new
end

Instance Method Details

#purge(key) ⇒ Object



151
152
153
154
# File 'lib/rack/cache/metastore.rb', line 151

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

#read(key) ⇒ Object



141
142
143
144
145
# File 'lib/rack/cache/metastore.rb', line 141

def read(key)
  @hash.fetch(key, []).collect do |req,res|
    [req.dup, res.dup]
  end
end

#to_hashObject



156
157
158
# File 'lib/rack/cache/metastore.rb', line 156

def to_hash
  @hash
end

#write(key, entries) ⇒ Object



147
148
149
# File 'lib/rack/cache/metastore.rb', line 147

def write(key, entries)
  @hash[key] = entries
end