Module: Waylon::BaseComponent::InstanceUtilityMethods

Defined in:
lib/waylon/base_component.rb

Overview

Base instance utility methods

Instance Method Summary collapse

Instance Method Details

#cache(key, expires: 600) ⇒ Object

Allows caching operations (or retrieving cached versions)

Parameters:

  • key (String)

    How to store/retrieved the cached value

  • expires (Integer) (defaults to: 600)

    How long to cache the value



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

Parameters:

  • key (String)

    The key name to lookup



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

#storageWaylon::Storage Also known as: db

A wrapper for accessing the persistent storage

Returns:



131
132
133
# File 'lib/waylon/base_component.rb', line 131

def storage
  Waylon::Storage
end