Skip to content

Commit

Permalink
Move memoizable cache to injected hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 27, 2015
1 parent ec30e1f commit 7f5b905
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/flipper/adapters/memoizable.rb
Expand Up @@ -5,9 +5,13 @@ module Adapters
class Memoizable < Decorator
FeaturesKey = :flipper_features

# Internal
attr_reader :cache

# Public
def initialize(adapter)
def initialize(adapter, cache = nil)
super(adapter)
@cache = cache || {}
end

# Public
Expand Down Expand Up @@ -68,11 +72,6 @@ def disable(feature, gate, thing)
result
end

# Internal
def cache
Thread.current[:flipper_memoize_cache] ||= {}
end

# Internal: Turns local caching on/off.
#
# value - The Boolean that decides if local caching is on.
Expand Down
4 changes: 2 additions & 2 deletions spec/flipper/adapters/memoizable_spec.rb
Expand Up @@ -7,9 +7,9 @@
let(:features_key) { described_class::FeaturesKey }
let(:adapter) { Flipper::Adapters::Memory.new }
let(:flipper) { Flipper.new(adapter) }
let(:cache) { subject.cache }
let(:cache) { {} }

subject { described_class.new(adapter) }
subject { described_class.new(adapter, cache) }

it_should_behave_like 'a flipper adapter'

Expand Down

0 comments on commit 7f5b905

Please sign in to comment.