Skip to content

Commit 00bb602

Browse files
authored
Merge pull request #932 from rosanelli/race_condition_ttl_for_activesupportcachestore_adpater
adds race_condition_ttl option for the ActiveSupportCacheStore adapter
2 parents 87e8674 + 46bf27d commit 00bb602

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/flipper/adapters/active_support_cache_store.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ module Adapters
77
# Public: Adapter that wraps another adapter with the ability to cache
88
# adapter calls in ActiveSupport::ActiveSupportCacheStore caches.
99
class ActiveSupportCacheStore < CacheBase
10-
def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, write_through: false, prefix: nil)
10+
11+
# Public: The race_condition_ttl for all cached data.
12+
attr_reader :race_condition_ttl
13+
14+
def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, race_condition_ttl: nil, write_through: false, prefix: nil)
1115
if expires_in == :none_provided
1216
ttl ||= nil
1317
else
@@ -18,6 +22,7 @@ def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, write_thro
1822
ttl = expires_in
1923
end
2024
super(adapter, cache, ttl, prefix: prefix)
25+
@race_condition_ttl = race_condition_ttl
2126
@write_through = write_through
2227
end
2328

@@ -73,6 +78,7 @@ def cache_delete(key)
7378
def write_options
7479
write_options = {}
7580
write_options[:expires_in] = @ttl if @ttl
81+
write_options[:race_condition_ttl] if @race_condition_ttl
7682
write_options
7783
end
7884
end

spec/flipper/adapters/active_support_cache_store_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
end
99
let(:cache) { ActiveSupport::Cache::MemoryStore.new }
1010
let(:write_through) { false }
11-
let(:adapter) { described_class.new(memory_adapter, cache, 10, write_through: write_through) }
11+
let(:race_condition_ttl) { 5 }
12+
let(:adapter) { described_class.new(memory_adapter, cache, 10, race_condition_ttl: race_condition_ttl, write_through: write_through) }
1213
let(:flipper) { Flipper.new(adapter) }
1314

1415
subject { adapter }
@@ -42,6 +43,15 @@
4243
expect(adapter.ttl).to be(nil)
4344
end
4445

46+
it "knows race_condition_ttl" do
47+
expect(adapter.race_condition_ttl).to eq(race_condition_ttl)
48+
end
49+
50+
it "knows default when no ttl or expires_in provided" do
51+
adapter = described_class.new(memory_adapter, cache)
52+
expect(adapter.race_condition_ttl).to be(nil)
53+
end
54+
4555
it "knows features_cache_key" do
4656
expect(adapter.features_cache_key).to eq("flipper/v1/features")
4757
end

0 commit comments

Comments
 (0)