Class: S3Browser::Store::StoreCache

Inherits:
Object
  • Object
show all
Defined in:
lib/s3browser/store.rb

Overview

A thread safe cache class, offering only #[] and #[]= methods, each protected by a mutex. Ripped off from Roda - github.com/jeremyevans/roda

Instance Method Summary collapse

Constructor Details

#initializeStoreCache

Create a new thread safe cache.



12
13
14
15
# File 'lib/s3browser/store.rb', line 12

def initialize
  @mutex = Mutex.new
  @hash = {}
end

Instance Method Details

#[](key) ⇒ Object

Make getting value from underlying hash thread safe.



18
19
20
# File 'lib/s3browser/store.rb', line 18

def [](key)
  @mutex.synchronize{@hash[key]}
end

#[]=(key, value) ⇒ Object

Make setting value in underlying hash thread safe.



23
24
25
# File 'lib/s3browser/store.rb', line 23

def []=(key, value)
  @mutex.synchronize{@hash[key] = value}
end