Module: Plezi::Base::HasCache

Included in:
BakeSASS
Defined in:
lib/plezi/render/has_cache.rb

Overview

Provides a thread-safe caching engine

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

initializes the cache



6
7
8
9
# File 'lib/plezi/render/has_cache.rb', line 6

def self.extended(base)
   base.instance_variable_set :@_lock, Mutex.new
   base.instance_variable_set :@_cache, {}.dup
end

Instance Method Details

#get(key) ⇒ Object Also known as: []

Retrieves data form the cache



17
18
19
# File 'lib/plezi/render/has_cache.rb', line 17

def get(key)
   @_lock.synchronize { @_cache[key] }
end

#store(key, value) ⇒ Object Also known as: []=

Stores data in the cache



12
13
14
# File 'lib/plezi/render/has_cache.rb', line 12

def store(key, value)
   @_lock.synchronize { @_cache[key] = value }
end