Class: Rack::DevInsight::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/dev_insight/storage/memory_store.rb

Constant Summary collapse

MAX_REAP_SEC =
2

Instance Method Summary collapse

Constructor Details

#initializeMemoryStore

Returns a new instance of MemoryStore.



8
9
10
11
12
# File 'lib/rack/dev_insight/storage/memory_store.rb', line 8

def initialize
  @lock = Mutex.new
  @cache = {}
  @memory_size = DevInsight.config.memory_store_size
end

Instance Method Details

#read(id) ⇒ Object



21
22
23
# File 'lib/rack/dev_insight/storage/memory_store.rb', line 21

def read(id)
  @lock.synchronize { @cache[id] }
end

#write(result) ⇒ Object



14
15
16
17
18
19
# File 'lib/rack/dev_insight/storage/memory_store.rb', line 14

def write(result)
  @lock.synchronize do
    @cache[result.id] = result
    reap_excess_memory
  end
end