Module: Adorn::Cache
- Defined in:
- lib/adorn/cache.rb
Class Method Summary collapse
-
.[](key) ⇒ Hash
Return value at given key from the Adorn::Cache.
-
.append!(key, value) ⇒ Hash
Instantiate or read from Adorn::Cache.
-
.clear! ⇒ Hash
Remove all values from the Adorn::Cache.
-
.semaphore ⇒ Mutex
Used to create a critical area during writes to Adorn::Cache.
Class Method Details
.[](key) ⇒ Hash
Return value at given key from the Adorn::Cache.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/adorn/cache.rb', line 37 def [](key) case key.class.to_s when 'String' Thread.current[:adorn_cache][key] when 'Symbol' Thread.current[:adorn_cache][key.to_s] else raise 'Unable to read key' end end |
.append!(key, value) ⇒ Hash
Instantiate or read from Adorn::Cache. Provide an interface to append to Adorn::Cache during request
25 26 27 28 29 30 31 |
# File 'lib/adorn/cache.rb', line 25 def append!(key, value) Thread.current[:adorn_cache] ||= Hash.new semaphore.synchronize do Thread.current[:adorn_cache].merge!({ "#{key}" => value }) end rescue nil #rescue ThreadError end |
.clear! ⇒ Hash
Remove all values from the Adorn::Cache.
52 53 54 55 56 |
# File 'lib/adorn/cache.rb', line 52 def clear! semaphore.synchronize do Thread.current[:adorn_cache].clear end rescue nil #rescue ThreadError end |
.semaphore ⇒ Mutex
Used to create a critical area during writes to Adorn::Cache
16 17 18 |
# File 'lib/adorn/cache.rb', line 16 def semaphore Thread.current[:semaphore] ||= Mutex.new end |