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)


114
115
116
117
# File 'lib/sparkle_formation/utils.rb', line 114

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

.[]=(k, v) ⇒ Object

Set value

Parameters:

  • k (Object)

    key

  • v (Object)

    value

Returns:

  • (Object)

    v



124
125
126
127
# File 'lib/sparkle_formation/utils.rb', line 124

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

.init!self

Initialize cache within thread

Returns:

  • (self)


132
133
134
135
136
137
# File 'lib/sparkle_formation/utils.rb', line 132

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