Last active
March 6, 2023 11:32
-
-
Save bkeepers/f5c52f817ec043d2a52053d408349e04 to your computer and use it in GitHub Desktop.
Use Flipper::Adapters::Poll to keep persisted features synced into memory. Polling happens in a background thread and loads all features into an in-memory adapter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "flipper/adapters/dual_write" | |
require "flipper/adapters/poll" | |
Flipper.configure do |config| | |
config.adapter do | |
# Primary storage adapter | |
storage_adapter = Flipper::Adapters::ActiveRecord.new | |
# Poll the primary storage adapter every 10 seconds to get all features | |
poller = Flipper::Adapters::Poll::Poller.get('memoizer', { | |
interval: 5, # seconds | |
remote_adapter: storage_adapter | |
}).tap(&:start) | |
# Perform initial sync from primary storage adapter | |
poller.sync | |
# Read from poller's memory adapter, write to both | |
Flipper::Adapters::DualWrite.new(poller.adapter, storage_adapter) | |
end | |
end | |
# Disable default memoization/preloading | |
Rails.application.configure do | |
config.flipper.memoize = false | |
config.flipper.preload = false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment