Class: Dassets::MemCache
- Inherits:
-
Object
- Object
- Dassets::MemCache
- Defined in:
- lib/dassets/cache.rb
Overview
This is a thread-safe in-memory cache.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ MemCache
constructor
A new instance of MemCache.
- #keys ⇒ Object
Constructor Details
#initialize ⇒ MemCache
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 |
#keys ⇒ Object
14 15 16 |
# File 'lib/dassets/cache.rb', line 14 def keys @hash.keys end |