Class: FHTTPClient::Cache::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/f_http_client/cache/rails.rb

Class Method Summary collapse

Class Method Details

.fetch(name, options = {}) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/f_http_client/cache/rails.rb', line 9

def fetch(name, options = {})
  raise RailsNotDefined unless defined?(::Rails)

  cache_entry = cache.read(name)

  return cache_entry if cache_entry.present?
  return unless block_given?

  result = yield

  cache.write(name, result, options) unless options[:skip_if]&.(result)

  result
end