Class: Dassets::MemCache

Inherits:
Object
  • Object
show all
Defined in:
lib/dassets/cache.rb

Overview

This is a thread-safe in-memory cache.

Instance Method Summary collapse

Constructor Details

#initializeMemCache

Returns a new instance of MemCache.



9
10
11
12
# File 'lib/dassets/cache.rb', line 9

def initialize
  @hash = {}
  @write_mutex = ::Mutex.new
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/dassets/cache.rb', line 18

def [](key)
  @hash[key]
end

#[]=(key, value) ⇒ Object



22
23
24
# File 'lib/dassets/cache.rb', line 22

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

#keysObject



14
15
16
# File 'lib/dassets/cache.rb', line 14

def keys
  @hash.keys
end