docbrown/config/initializers/flipper.rb
Jamie Gaskins 5fc3f52299
Allow caching feature flags for a given duration (#14668)
This duration is specified in the `CACHE_FEATURE_FLAGS_SECONDS`
environment variable. It can't be updated without restarting the
application.
2021-09-07 10:19:29 -04:00

15 lines
522 B
Ruby

Flipper.configure do |config|
config.default do
adapter = if (cache_duration = ENV["CACHE_FEATURE_FLAGS_SECONDS"])
Flipper::Adapters::ActiveSupportCacheStore.new(
Flipper::Adapters::ActiveRecord.new,
ActiveSupport::Cache::MemoryStore.new(expires_in: cache_duration.to_i.seconds),
)
else
Flipper::Adapters::ActiveRecord.new
end
# pass adapter to handy DSL instance
Flipper.new(adapter)
end
end