Module: Waylon::BaseComponent::InstanceUtilityMethods
- Defined in:
- lib/waylon/base_component.rb
Overview
Base instance utility methods
Instance Method Summary collapse
-
#cache(key, expires: 600) ⇒ Object
Allows caching operations (or retrieving cached versions).
-
#config(key) ⇒ Object
A wrapper for access to a namespaced Config key.
-
#storage ⇒ Waylon::Storage
(also: #db)
A wrapper for accessing the persistent storage.
Instance Method Details
#cache(key, expires: 600) ⇒ Object
Allows caching operations (or retrieving cached versions)
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/waylon/base_component.rb', line 111 def cache(key, expires: 600) cache_key = self.class.config_key_for(key) if !Waylon::Cache.key?(cache_key) && block_given? result = yield Waylon::Cache.store(cache_key, result, expires:) elsif !Waylon::Cache.key?(cache_key) return nil end Waylon::Cache.load(cache_key, expires:) end |
#config(key) ⇒ Object
A wrapper for access to a namespaced Config key
124 125 126 127 |
# File 'lib/waylon/base_component.rb', line 124 def config(key) conf = Config.instance conf[self.class.config_key_for(key)] end |
#storage ⇒ Waylon::Storage Also known as: db
A wrapper for accessing the persistent storage
131 132 133 |
# File 'lib/waylon/base_component.rb', line 131 def storage Waylon::Storage end |