Method: LogicalModel::Cache::ClassMethods#async_find_with_cache

Defined in:
lib/logical_model/cache.rb

#async_find_with_cache(id, params = {}, &block) ⇒ Object Also known as: async_find



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/logical_model/cache.rb', line 91

def async_find_with_cache(id, params = {}, &block)
  # Generate key based on params
  cache_key = self.cache_key(id, params)
  # If there is a cached value return it
  self.logger.debug "LogicalModel Log CACHE: Reading cache key=#{cache_key}"
  cached_result = self.cache_store.read(cache_key)
  if cached_result
    yield cached_result
  else
    self.logger.debug 'LogicalModel Log CACHE: Cache not present. Calling find_async without cache'
    async_find_without_cache(id, params, &block)
  end
end