Class: KonoUtilsBootstrapView4::ConceptCacher
- Inherits:
-
Object
- Object
- KonoUtilsBootstrapView4::ConceptCacher
- 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
- #_cache ⇒ Hash readonly
Instance Method Summary collapse
- #clear ⇒ Object
-
#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.
-
#initialize ⇒ ConceptCacher
constructor
A new instance of ConceptCacher.
-
#store(key, value) ⇒ Object
Store del valore.
Constructor Details
#initialize ⇒ ConceptCacher
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
#_cache ⇒ Hash (readonly)
7 8 9 |
# File 'lib/kono_utils_bootstrap_view4/concept_cacher.rb', line 7 def _cache @_cache end |
Instance Method Details
#clear ⇒ Object
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
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 |