Skip to content

Commit

Permalink
make users who do not use fault_tolerant not go into new code
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jun 6, 2020
1 parent 46ddfda commit 97819fb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/rack/cache/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ def lookup
entry
else
record :stale
validate_with_stale_cache_failover(entry)
if fault_tolerant?
validate_with_stale_cache_failover(entry)
else
validate(entry)
end
end
else
record :miss
Expand All @@ -196,19 +200,13 @@ def lookup

# Returns stale cache on exception.
def validate_with_stale_cache_failover(entry)
begin
validate(entry)
rescue => e
if fault_tolerant?
record :connnection_failed
age = entry.age.to_s
entry.headers['Age'] = age
record "Fail-over to stale cache data with age #{age} due to #{e.class.name}: #{e}"
entry
else
raise
end
end
validate(entry)
rescue => e
record :connnection_failed
age = entry.age.to_s
entry.headers['Age'] = age
record "Fail-over to stale cache data with age #{age} due to #{e.class.name}: #{e}"
entry
end

# Validate that the cache entry is fresh. The original request is used
Expand Down

0 comments on commit 97819fb

Please sign in to comment.