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)


92
93
94
95
# File 'lib/sparkle_formation/utils.rb', line 92

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

.[]=(k, v) ⇒ Object

Set value

Parameters:

  • k (Object)

    key

  • v (Object)

    value

Returns:

  • (Object)

    v



102
103
104
105
# File 'lib/sparkle_formation/utils.rb', line 102

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

.init!self

Initialize cache within thread

Returns:

  • (self)


110
111
112
113
114
115
# File 'lib/sparkle_formation/utils.rb', line 110

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