Class: Flipflop::FeatureCache
- Inherits:
-
Object
- Object
- Flipflop::FeatureCache
- Defined in:
- lib/flipflop/feature_cache.rb
Defined Under Namespace
Classes: Middleware
Class Method Summary collapse
Instance Method Summary collapse
- #clear! ⇒ Object
- #disable! ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize ⇒ FeatureCache
constructor
A new instance of FeatureCache.
Constructor Details
#initialize ⇒ FeatureCache
Returns a new instance of FeatureCache.
32 33 34 35 |
# File 'lib/flipflop/feature_cache.rb', line 32 def initialize @enabled = false @cache = {} end |
Class Method Details
.current ⇒ Object
24 25 26 27 |
# File 'lib/flipflop/feature_cache.rb', line 24 def current Thread.current.thread_variable_get(:flipflop_cache) or Thread.current.thread_variable_set(:flipflop_cache, new) end |
Instance Method Details
#clear! ⇒ Object
41 42 43 |
# File 'lib/flipflop/feature_cache.rb', line 41 def clear! @cache.clear end |
#disable! ⇒ Object
49 50 51 52 |
# File 'lib/flipflop/feature_cache.rb', line 49 def disable! @enabled = false @cache.clear end |
#enable! ⇒ Object
45 46 47 |
# File 'lib/flipflop/feature_cache.rb', line 45 def enable! @enabled = true end |
#enabled? ⇒ Boolean
37 38 39 |
# File 'lib/flipflop/feature_cache.rb', line 37 def enabled? @enabled end |
#fetch(key) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/flipflop/feature_cache.rb', line 54 def fetch(key) if @enabled @cache.fetch(key) do @cache[key] = yield end else yield end end |