Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created March 14, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeepers/3320e5bf518f352f2edfe32a3d1c775b to your computer and use it in GitHub Desktop.
Save bkeepers/3320e5bf518f352f2edfe32a3d1c775b to your computer and use it in GitHub Desktop.
Use Sync adapter to keep memory in sync with storage adapter
# config/initializers/flipper.rb
require 'flipper/adapters/sync'
Rails.application.configure do
# Disable per-request memoization
config.flipper.memoize = false
end
Flipper.configure do |config|
config.adapter do
# Primary storage adapter
storage_adapter = Flipper::Adapters::ActiveRecord.new
# Memory adapter for fast reads
memory_adapter = Flipper::Adapters::Memory.new
# Keep in sync in main thread on an interval
Flipper::Adapters::Sync.new(memory_adapter, storage_adapter, interval: 10)
end
end
@jhubert
Copy link

jhubert commented Mar 14, 2023

@bkeepers Does this require a specific branch, or can this be done with main?

@bkeepers
Copy link
Author

@jhubert This works on main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment