Flipper Cloud



By default, Flipper will preload and memoize all features to ensure one adapter call per request. This means no matter how many times you check features, Flipper will only make one network request to Postgres, MySQL, Redis, Mongo or whatever adapter you are using for the length of the request.


Flipper will preload all features before each request by default, which is recommended if:

  • you have a limited number of features (< 100?)
  • most of your requests depend on most of your features
  • you have limited gate data combined across all features (< 1k enabled gates, like individual actors, across all features)

The reason for these recommendations is that more features and gates means more data being preloaded for every request. The general rule is: leave preloading on until performance is negatively affected at which point it has served its purpose and should be turned off. You can track performance by instrumenting flipper usage to your favorite metrics system.

If you need to customize preloading, it's very easy:

# config/initializers/flipper.rb
Rails.application.configure do
  # Load specific features that are used on most requests
  config.flipper.preload = [:stats, :search, :some_feature]

  # Or completely disable preloading
  config.flipper.preload = false

Features that are not preloaded are still memoized, ensuring one adapter call per feature during a request.

Skip memoization

Prevent preloading and memoization on specific requests by setting memoize to a proc that evaluates to false.

# config/initializers/flipper.rb
Rails.application.configure do
  config.flipper.memoize = ->(request) { !request.path.start_with?("/assets") }

Disable memoization

To disable memoization entirely:

Rails.application.configure do
  config.flipper.memoize = false

Advanced (non-Rails usage)

Memoization is implemented as a Rack middleware, which can be used manually in any Ruby app:

use Flipper::Middleware::Memoizer,
  preload: true,
  unless: ->(request) { request.path.start_with?("/assets") }

Also Note: If you need to customize the instance of Flipper used by the memoizer, you can pass the instance to SetupEnv:

use Flipper::Middleware::SetupEnv, -> { Flipper.new(...) }
use Flipper::Middleware::Memoizer

Cache Adapters

Cache adapters allow you to cache adapter calls for longer than a single request and should be used alongside the memoization middleware to add another caching layer.


Dalli is a high performance pure Ruby client for accessing memcached servers.


Example using the Dalli cache adapter with the Memory adapter and a TTL of 600 seconds:

Flipper.configure do |config|
  config.adapter do
    dalli = Dalli::Client.new('localhost:11211')
    adapter = Flipper::Adapters::Memory.new
    Flipper::Adapters::Dalli.new(adapter, dalli, 600)


Applications using Redis via the redis-rb client can take advantage of the RedisCache adapter.

Initialize RedisCache with a flipper adapter, a Redis client instance, and an optional TTL in seconds. TTL defaults to 3600 seconds.

Example using the RedisCache adapter with the Memory adapter and a TTL of 4800 seconds:

require 'flipper/adapters/redis_cache'

Flipper.configure do |config|
  config.adapter do
    redis = Redis.new(url: ENV['REDIS_URL'])
    memory_adapter = Flipper::Adapters::Memory.new
    Flipper::Adapters::RedisCache.new(memory_adapter, redis, 4800)


Rails applications can cache Flipper calls in any ActiveSupport::Cache::Store implementation.

Add this line to your application's Gemfile:

gem 'flipper-active_support_cache_store'

And then execute:

$ bundle

Or install it yourself with:

$ gem install flipper-active_support_cache_store

Example using the ActiveSupportCacheStore adapter with ActiveSupport's MemoryStore, Flipper's Memory adapter, and a TTL of 5 minutes.

require 'active_support/cache'
require 'flipper/adapters/active_support_cache_store'

Flipper.configure do |config|
  config.adapter do
      ActiveSupport::Cache::MemoryStore.new # Or Rails.cache,
      expires_in: 5.minutes

Setting expires_in is optional and will set an expiration time on Flipper cache keys. If specified, all flipper keys will use this expires_in over the expires_in passed to your ActiveSupport cache constructor.

Start flipping features with Flipper Cloud to get support, audit history, finer-grained permissions, multi-environment sync, and all of your projects in one place.

Prefer our open source Cloudless option? You can also choose from several tiers to sponsor Flipper on GitHub.