Class: Roda::RodaPlugins::PerThreadCaching::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/roda/plugins/per_thread_caching.rb

Constant Summary collapse

MUTEX =

Mutex used to ensure multiple per-thread caches don’t use the same key

::Mutex.new
N =

Auto incrementing number proc used to make sure multiple thread-thread caches don’t use the same key.

lambda{MUTEX.synchronize{n += 1}}

Instance Method Summary collapse

Constructor Details

#initializeCache

Store unique symbol used to look up in the per thread caches.



38
39
40
# File 'lib/roda/plugins/per_thread_caching.rb', line 38

def initialize
  @o = :"roda_per_thread_cache_#{N.call}"
end

Instance Method Details

#[](key) ⇒ Object

Return the current thread’s cached value.



43
44
45
# File 'lib/roda/plugins/per_thread_caching.rb', line 43

def [](key)
  _hash[key]
end

#[]=(key, value) ⇒ Object

Set the current thread’s cached value.



48
49
50
# File 'lib/roda/plugins/per_thread_caching.rb', line 48

def []=(key, value)
  _hash[key] = value
end