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)


74
75
76
77
# File 'lib/sparkle_formation/utils.rb', line 74

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

.[]=(k, v) ⇒ Object

Set value

Parameters:

  • k (Object)

    key

  • v (Object)

    value

Returns:

  • (Object)

    v



84
85
86
87
# File 'lib/sparkle_formation/utils.rb', line 84

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

.init!self

Initialize cache within thread

Returns:

  • (self)


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

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