docs/Optimization.md in flipper-0.10.2 vs docs/Optimization.md in flipper-0.11.0.beta1

- old
+ new

@@ -10,12 +10,14 @@ ```ruby # create flipper dsl instance, see above Usage for more details flipper = Flipper.new(...) +require 'flipper/middleware/setup_env' require 'flipper/middleware/memoizer' -config.middleware.use Flipper::Middleware::Memoizer, flipper +config.middleware.use Flipper::Middleware::SetupEnv, flipper +config.middleware.use Flipper::Middleware::Memoizer ``` If you set your flipper instance up in an initializer, you can pass a block to the middleware and it will lazily load the instance the first time the middleware is invoked. ```ruby @@ -25,29 +27,32 @@ @flipper ||= Flipper.new(...) end end # config/application.rb -config.middleware.use Flipper::Middleware::Memoizer, lambda { +require 'flipper/middleware/setup_env' +require 'flipper/middleware/memoizer' +config.middleware.use Flipper::Middleware::SetupEnv, lambda { MyRailsApp.flipper } +config.middleware.use Flipper::Middleware::Memoizer ``` **Note**: Be sure that the middleware is high enough up in your stack that all feature checks are wrapped. ### Options The Memoizer middleware also supports a few options. Use either `preload` or `preload_all`, not both. * **`:preload`** - An `Array` of feature names (`Symbol`) to preload for every request. Useful if you have features that are used on every endpoint. `preload` uses `Adapter#get_multi` to attempt to load the features in one network call instead of N+1 network calls. ```ruby - config.middleware.use Flipper::Middleware::Memoizer, flipper, + config.middleware.use Flipper::Middleware::Memoizer, preload: [:stats, :search, :some_feature] ``` -* **`:preload_all`** - A Boolean value (default: false) of whether or not all features should be preloaded. Using this results in a `preload` call with the result of `Adapter#features`. Any subsequent feature checks will be memoized and perform no network calls. I wouldn't recommend using this unless you have few features (< 30?) and nearly all of them are used on every request. +* **`:preload_all`** - A Boolean value (default: false) of whether or not all features should be preloaded. Using this results in a `preload` call with the result of `Adapter#features`. Any subsequent feature checks will be memoized and perform no network calls. I wouldn't recommend using this unless you have few features (< 30?) and nearly all of them are used on every request. ```ruby - config.middleware.use Flipper::Middleware::Memoizer, flipper, + config.middleware.use Flipper::Middleware::Memoizer, preload_all: true ``` ## Cache Adapters @@ -64,6 +69,23 @@ ```ruby dalli_client = Dalli::Client.new('localhost:11211') memory_adapter = Flipper::Adapters::Memory.new adapter = Flipper::Adapters::Dalli.new(memory_adapter, dalli_client, 600) flipper = Flipper.new(adapter) +``` +### RedisCache + +Applications using [Redis](https://redis.io/) via the [redis-rb](https://github.com/redis/redis-rb) client can take advantage of the RedisCache adapter. + +Initialize `RedisCache` with a flipper [adapter](https://github.com/jnunemaker/flipper/blob/master/docs/Adapters.md), 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: + +```ruby + require 'flipper/adapters/memory' + require 'flipper/adapters/redis_cache' + + redis = Redis.new(url: ENV['REDIS_URL']) + memory_adapter = Flipper::Adapters::Memory.new + adapter = Flipper::Adapters::RedisCache.new(memory_adapter, redis, 4800) + flipper = Flipper.new(adapter) ```