Skip to content
This repository was archived by the owner on Jan 22, 2022. It is now read-only.

Commit 5418bbe

Browse files
author
Tom Scott
committed
Support recylcable cache keys
This reverts commit 5797f2d, which reverted the original commit caa99fc that added this into master prematurely. Future 5.0 changes will be contained in branch 'v5.0', and changes for 5.1 will be made here in 'master'.
1 parent 99d6235 commit 5418bbe

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/active_support/cache/redis_store.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def initialize(*addresses)
7171
def write(name, value, options = nil)
7272
options = merged_options(options)
7373
instrument(:write, name, options) do |payload|
74-
entry = options[:raw].present? ? value : Entry.new(value, options)
7574
if options[:expires_in].present? && options[:race_condition_ttl].present? && options[:raw].blank?
7675
options[:expires_in] = options[:expires_in].to_f + options[:race_condition_ttl].to_f
7776
end
77+
entry = options[:raw].present? ? value : Entry.new(value, options)
7878
write_entry(normalize_key(name, options), entry, options)
7979
end
8080
end
@@ -305,7 +305,6 @@ def key_matcher(pattern, options)
305305
end
306306

307307
private
308-
309308
if ActiveSupport::VERSION::MAJOR < 5
310309
def normalize_key(*args)
311310
namespaced_key(*args)

test/active_support/cache/redis_store_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,20 @@ def setup
377377

378378
describe "race_condition_ttl on fetch" do
379379
it "persist entry for longer than given ttl" do
380-
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
380+
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
381381
@store.fetch("rabbit", options) { @rabbit }
382382
sleep 1.1
383383
@store.delete("rabbit").must_equal(1)
384384
end
385385

386386
it "limits stampede time to read-write duration" do
387387
first_rabbit = second_rabbit = nil
388-
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
388+
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
389389
@store.fetch("rabbit", options) { @rabbit }
390390
sleep 1
391391

392392
th1 = Thread.new do
393-
first_rabbit = @store.fetch("rabbit", race_condition_ttl: 2) do
393+
first_rabbit = @store.fetch("rabbit", options) do
394394
sleep 1
395395
@white_rabbit
396396
end

0 commit comments

Comments
 (0)