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.



41
42
43
# File 'lib/roda/plugins/per_thread_caching.rb', line 41

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

Instance Method Details

#[](key) ⇒ Object

Return the current thread’s cached value.



46
47
48
# File 'lib/roda/plugins/per_thread_caching.rb', line 46

def [](key)
  _hash[key]
end

#[]=(key, value) ⇒ Object

Set the current thread’s cached value.



51
52
53
# File 'lib/roda/plugins/per_thread_caching.rb', line 51

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