Module: Mobility::Plugins::Cache
- Defined in:
- lib/mobility/plugins/cache.rb,
lib/mobility/plugins/cache/translation_cacher.rb
Overview
Caches values fetched from the backend so subsequent fetches can be performed more quickly. The cache stores cached values in a simple hash, which is not optimal for some storage strategies, so some backends (KeyValue, Table) use a custom module through the Backend::Setup#apply_plugin hook. For details see the documentation for these backends.
The cache is reset when one of a set of events happens (saving, reloading, etc.). See BackendResetter for details.
Values are added to the cache in two ways:
-
first read from backend
-
any write to backend
Defined Under Namespace
Classes: TranslationCacher
Class Method Summary collapse
-
.apply(attributes, option) ⇒ Object
Applies cache plugin to attributes.
Instance Method Summary collapse
-
#write(locale, value, **options) ⇒ Object
Updates translation for provided locale without calling backend’s methods to persist the changes.
Class Method Details
.apply(attributes, option) ⇒ Object
Applies cache plugin to attributes.
26 27 28 29 30 31 32 33 34 |
# File 'lib/mobility/plugins/cache.rb', line 26 def self.apply(attributes, option) if option backend_class = attributes.backend_class backend_class.include(self) unless backend_class.apply_plugin(:cache) model_class = attributes.model_class model_class.include BackendResetter.for(model_class).new(attributes.names) { clear_cache } end end |
Instance Method Details
#write(locale, value, **options) ⇒ Object
Updates translation for provided locale without calling backend’s methods to persist the changes.
47 48 49 50 |
# File 'lib/mobility/plugins/cache.rb', line 47 def write(locale, value, **) return super if .delete(:cache) == false cache[locale] = super end |