Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/flipper/adapters/active_support_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ module Adapters
# Public: Adapter that wraps another adapter with the ability to cache
# adapter calls in ActiveSupport::ActiveSupportCacheStore caches.
class ActiveSupportCacheStore < CacheBase
def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, write_through: false, prefix: nil)

# Public: The race_condition_ttl for all cached data.
attr_reader :race_condition_ttl

def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, race_condition_ttl: nil, write_through: false, prefix: nil)
if expires_in == :none_provided
ttl ||= nil
else
Expand All @@ -18,6 +22,7 @@ def initialize(adapter, cache, ttl = nil, expires_in: :none_provided, write_thro
ttl = expires_in
end
super(adapter, cache, ttl, prefix: prefix)
@race_condition_ttl = race_condition_ttl
@write_through = write_through
end

Expand Down Expand Up @@ -73,6 +78,7 @@ def cache_delete(key)
def write_options
write_options = {}
write_options[:expires_in] = @ttl if @ttl
write_options[:race_condition_ttl] if @race_condition_ttl
write_options
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/flipper/adapters/active_support_cache_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
end
let(:cache) { ActiveSupport::Cache::MemoryStore.new }
let(:write_through) { false }
let(:adapter) { described_class.new(memory_adapter, cache, 10, write_through: write_through) }
let(:race_condition_ttl) { 5 }
let(:adapter) { described_class.new(memory_adapter, cache, 10, race_condition_ttl: race_condition_ttl, write_through: write_through) }
let(:flipper) { Flipper.new(adapter) }

subject { adapter }
Expand Down Expand Up @@ -42,6 +43,15 @@
expect(adapter.ttl).to be(nil)
end

it "knows race_condition_ttl" do
expect(adapter.race_condition_ttl).to eq(race_condition_ttl)
end

it "knows default when no ttl or expires_in provided" do
adapter = described_class.new(memory_adapter, cache)
expect(adapter.race_condition_ttl).to be(nil)
end

it "knows features_cache_key" do
expect(adapter.features_cache_key).to eq("flipper/v1/features")
end
Expand Down