Class: KonoUtilsBootstrapView4::ConceptCacher

Inherits:
Object
  • Object
show all
Defined in:
lib/kono_utils_bootstrap_view4/concept_cacher.rb

Overview

PORO per l’esecuzione della cache a livello di istanza applicazione dei nomi di classe da utilizzare per i vari componenti dei modelli

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConceptCacher

Returns a new instance of ConceptCacher.



9
10
11
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 9

def initialize
  @_cache = {}
end

Instance Attribute Details

#_cacheHash (readonly)

Returns:

  • (Hash)


7
8
9
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 7

def _cache
  @_cache
end

Instance Method Details

#clearObject



13
14
15
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 13

def clear
  @_cache = {}
end

#get(key) {|| ... } ⇒ Object

Ritorna il valore cachato, se non è presente, allora verrà dato in pasto allo yield l’istanza di cache, e sarà chi la utilizzerà che si occuperà di salvare o meno il dato richiamato il metodo store passando il relativo valore da salvare

Parameters:

  • key (String)

Yield Parameters:

Returns:

  • (Object)

    Cached result



24
25
26
27
28
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 24

def get(key)
  return @_cache[key] if @_cache.key?(key)
  yield(self)
  @_cache[key]
end

#store(key, value) ⇒ Object

Store del valore



32
33
34
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 32

def store(key, value)
  @_cache[key] = value
end