module Adorn::Cache

Public Class Methods

[](key) click to toggle source

Return value at given key from the Adorn::Cache.

@param [Symbol, String] @return [Hash]

# 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) click to toggle source

Instantiate or read from Adorn::Cache. Provide an interface to append to Adorn::Cache during request

@param [Symbol, *] @return [Hash]

# 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!() click to toggle source

Remove all values from the Adorn::Cache.

@return [Hash]

# File lib/adorn/cache.rb, line 52
def clear!
  semaphore.synchronize do
    Thread.current[:adorn_cache].clear
  end rescue nil #rescue ThreadError
end
semaphore() click to toggle source

Used to create a critical area during writes to Adorn::Cache

@return [Mutex]

# File lib/adorn/cache.rb, line 16
def semaphore
  Thread.current[:semaphore] ||= Mutex.new
end