Class: SparkleFormation::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkle_formation/utils.rb

Overview

Cache helper

Class Method Summary collapse

Class Method Details

.[](k) ⇒ Object

Get value

Parameters:

  • k (Object)

Returns:

  • (Object)


108
109
110
111
# File 'lib/sparkle_formation/utils.rb', line 108

def [](k)
  init!
  Thread.current[:sparkle_cache][k]
end

.[]=(k, v) ⇒ Object

Set value

Parameters:

  • k (Object)

    key

  • v (Object)

    value

Returns:

  • (Object)

    v



118
119
120
121
# File 'lib/sparkle_formation/utils.rb', line 118

def []=(k, v)
  init!
  Thread.current[:sparkle_cache][k] = v
end

.init!self

Initialize cache within thread

Returns:

  • (self)


126
127
128
129
130
131
# File 'lib/sparkle_formation/utils.rb', line 126

def init!
  unless Thread.current[:sparkle_cache]
    Thread.current[:sparkle_cache] = {}
  end
  self
end