One of the not very elegant ways is to raise the erros.
def my_method(path)
Rails.cache.fetch(path, expires_in: 10.minutes, race_condition_ttl: 10) do
response = My::api.get path
raise MyCachePreventingError unless response.status == 200
JSON.parse response.body
end
rescue MyCachePreventingError
nil
end
If anyone has a better way I would like to know
source
share