flipper 0.21.0.rc1 → 0.22.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +12 -16
- data/.github/workflows/examples.yml +56 -0
- data/Changelog.md +54 -0
- data/Gemfile +1 -0
- data/README.md +2 -1
- data/docker-compose.yml +37 -34
- data/docs/Adapters.md +9 -10
- data/docs/Caveats.md +2 -2
- data/docs/Optimization.md +70 -47
- data/docs/api/README.md +5 -5
- data/docs/http/README.md +12 -11
- data/docs/read-only/README.md +8 -5
- data/examples/api/basic.ru +19 -0
- data/examples/api/custom_memoized.ru +37 -0
- data/examples/api/memoized.ru +43 -0
- data/examples/configuring_default.rb +1 -3
- data/examples/instrumentation_last_accessed_at.rb +37 -0
- data/examples/memoizing.rb +2 -5
- data/lib/flipper/adapters/pstore.rb +4 -0
- data/lib/flipper/adapters/sync/synchronizer.rb +2 -1
- data/lib/flipper/configuration.rb +29 -3
- data/lib/flipper/middleware/memoizer.rb +30 -15
- data/lib/flipper/railtie.rb +46 -0
- data/lib/flipper/version.rb +1 -1
- data/lib/flipper.rb +3 -1
- data/spec/flipper/configuration_spec.rb +16 -1
- data/spec/flipper/middleware/memoizer_spec.rb +94 -34
- data/spec/flipper/railtie_spec.rb +69 -0
- data/spec/helper.rb +2 -2
- data/spec/support/spec_helpers.rb +17 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14514238ff1ea823df0cefeb2e1048816b86995d582e6c3dda037d36db344078
|
4
|
+
data.tar.gz: 285650a29a45623ed0468a08736621ccf88a6453eeadd8f42a29740a4a2955bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af99a75cafb349025fd03a6c2bab4bb224f76acd2a0ac820bf6306ded28235b615fc0f891ce8d3df7612eca26d631fc7a51fb6ee738fdfdb614a561b121af04
|
7
|
+
data.tar.gz: bbaa9c0da5be73f4d1ab4ebc284919585878162e2c0151e346d77ad6909fddff7d0da7eff823ad29281d645e521d53e21f1de9184efda072e90e919d465a2c48
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
name: CI
|
2
|
-
on:
|
3
|
-
push:
|
4
|
-
branches: [master]
|
5
|
-
pull_request:
|
2
|
+
on: [push, pull_request]
|
6
3
|
jobs:
|
7
|
-
|
4
|
+
test:
|
5
|
+
name: Test on ruby ${{ matrix.ruby }} and rails ${{ matrix.rails }}
|
8
6
|
runs-on: ubuntu-latest
|
9
7
|
services:
|
10
8
|
redis:
|
@@ -18,8 +16,8 @@ jobs:
|
|
18
16
|
strategy:
|
19
17
|
matrix:
|
20
18
|
ruby: ['2.5', '2.6', '2.7']
|
19
|
+
rails: ['5.2', '6.0.0', '6.1.0']
|
21
20
|
env:
|
22
|
-
RAILS_VERSION: 6.0.0
|
23
21
|
SQLITE3_VERSION: 1.4.1
|
24
22
|
REDIS_URL: redis://localhost:6379/0
|
25
23
|
CI: true
|
@@ -36,10 +34,10 @@ jobs:
|
|
36
34
|
uses: actions/cache@v1
|
37
35
|
with:
|
38
36
|
path: vendor/bundle
|
39
|
-
key: ${{ runner.os }}-
|
37
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
|
40
38
|
restore-keys: |
|
41
|
-
${{ runner.os }}-
|
42
|
-
- name: Set up Ruby
|
39
|
+
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-
|
40
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
43
41
|
uses: actions/setup-ruby@v1
|
44
42
|
with:
|
45
43
|
ruby-version: ${{ matrix.ruby }}
|
@@ -47,11 +45,9 @@ jobs:
|
|
47
45
|
run: sudo apt-get -yqq install libpq-dev
|
48
46
|
- name: Install bundler
|
49
47
|
run: gem install bundler
|
50
|
-
- name: Run
|
51
|
-
run: bundle install --jobs 4 --retry 3
|
52
|
-
- name: Run Rake
|
53
|
-
run: bundle exec rake
|
54
|
-
- name: Run Examples
|
48
|
+
- name: Run Rake with Rails ${{ matrix.rails }}
|
55
49
|
env:
|
56
|
-
|
57
|
-
run:
|
50
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
51
|
+
run: |
|
52
|
+
bundle install --jobs 4 --retry 3
|
53
|
+
bundle exec rake
|
@@ -0,0 +1,56 @@
|
|
1
|
+
name: Examples
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
name: Test on ruby ${{ matrix.ruby }} and rails ${{ matrix.rails }}
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
services:
|
8
|
+
redis:
|
9
|
+
image: redis
|
10
|
+
ports: ['6379:6379']
|
11
|
+
options: >-
|
12
|
+
--health-cmd "redis-cli ping"
|
13
|
+
--health-interval 10s
|
14
|
+
--health-timeout 5s
|
15
|
+
--health-retries 5
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby: ['2.5', '2.6', '2.7']
|
19
|
+
rails: ['5.2', '6.0.0', '6.1.0']
|
20
|
+
env:
|
21
|
+
SQLITE3_VERSION: 1.4.1
|
22
|
+
REDIS_URL: redis://localhost:6379/0
|
23
|
+
CI: true
|
24
|
+
steps:
|
25
|
+
- name: Setup memcached
|
26
|
+
uses: KeisukeYamashita/memcached-actions@v1
|
27
|
+
- name: Start MongoDB
|
28
|
+
uses: supercharge/mongodb-github-action@1.3.0
|
29
|
+
with:
|
30
|
+
mongodb-version: 4.0
|
31
|
+
- name: Check out repository code
|
32
|
+
uses: actions/checkout@v2
|
33
|
+
- name: Do some action caching
|
34
|
+
uses: actions/cache@v1
|
35
|
+
with:
|
36
|
+
path: vendor/bundle
|
37
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
|
38
|
+
restore-keys: |
|
39
|
+
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-
|
40
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
41
|
+
uses: actions/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: ${{ matrix.ruby }}
|
44
|
+
- name: Install libpq-dev
|
45
|
+
run: sudo apt-get -yqq install libpq-dev
|
46
|
+
- name: Install bundler
|
47
|
+
run: gem install bundler
|
48
|
+
- name: Bundle install with Rails ${{ matrix.rails }}
|
49
|
+
env:
|
50
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
51
|
+
run: bundle install --jobs 4 --retry 3
|
52
|
+
- name: Run Examples with Rails ${{ matrix.rails }}
|
53
|
+
env:
|
54
|
+
FLIPPER_CLOUD_TOKEN: ${{ secrets.FLIPPER_CLOUD_TOKEN }}
|
55
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
56
|
+
run: script/examples
|
data/Changelog.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.22.1
|
2
|
+
|
3
|
+
## Additions/Changes
|
4
|
+
|
5
|
+
* Remove Octicons and replace with a pure CSS status circle (https://github.com/jnunemaker/flipper/pull/547)
|
6
|
+
* Rescue unique errors in AR and Sequel when setting value (https://github.com/jnunemaker/flipper/commit/87f5a98bce7baad7a27b75b5bce3256967769f27)
|
7
|
+
* Add a Content-Security-Policy to flipper-ui (https://github.com/jnunemaker/flipper/pull/552)
|
8
|
+
* Fix Synchronizer issue that occurs for ActiveRecord adapter (https://github.com/jnunemaker/flipper/pull/554)
|
9
|
+
|
10
|
+
## 0.22.0
|
11
|
+
|
12
|
+
## Additions/Changes
|
13
|
+
|
14
|
+
* Enable log subscriber by default in Rails (https://github.com/jnunemaker/flipper/pull/525)
|
15
|
+
* Remove memoizer from API and UI (https://github.com/jnunemaker/flipper/pull/527). If you are using the UI or API without configuring the default instance of Flipper, you'll need to enable memoization if you want it. For examples, see the examples/ui and examples/api directories.
|
16
|
+
* Fix SQL reserved word use in get_all for ActiveRecord and Sequel (https://github.com/jnunemaker/flipper/pull/536).
|
17
|
+
* Handle spaces in names gracefully in UI (https://github.com/jnunemaker/flipper/pull/541).
|
18
|
+
|
1
19
|
## 0.21.0
|
2
20
|
|
3
21
|
### Additions/Changes
|
@@ -7,6 +25,41 @@
|
|
7
25
|
* Added cloud recommendation to flipper-ui. Can be disabled with `Flipper::UI.configure { |config| config.cloud_recommendation = false }`. Just want to raise awareness that more is available if people want it (https://github.com/jnunemaker/flipper/pull/504)
|
8
26
|
* Added default `flipper_id` implementation via `Flipper::Identifier` and automatically included it in ActiveRecord and Sequel models (https://github.com/jnunemaker/flipper/pull/505)
|
9
27
|
* Deprecate superflous sync_method setting (https://github.com/jnunemaker/flipper/pull/511)
|
28
|
+
* Flipper is now pre-configured when used with Rails. By default, it will [memoize and preload all features for each request](docs/Optimization.md#memoization). (https://github.com/jnunemaker/flipper/pull/506)
|
29
|
+
|
30
|
+
### Upgrading
|
31
|
+
|
32
|
+
You should be able to upgrade to 0.21 without any breaking changes. However, if you want to simplify your setup, you can remove some configuration that is now handled automatically:
|
33
|
+
|
34
|
+
1. Adapters are configured when on require, so unless you are using caching or other customizations, you can remove adapter configuration.
|
35
|
+
|
36
|
+
```diff
|
37
|
+
# config/initializers/flipper.rb
|
38
|
+
- Flipper.configure do |config|
|
39
|
+
- config.default { Flipper.new(Flipper::Adapters::ActiveRecord.new) }
|
40
|
+
- end
|
41
|
+
```
|
42
|
+
|
43
|
+
2. `Flipper::Middleware::Memoizer` will be enabled by default.
|
44
|
+
|
45
|
+
```diff
|
46
|
+
# config/initializers/flipper.rb
|
47
|
+
- Rails.configuration.middleware.use Flipper::Middleware::Memoizer,
|
48
|
+
- preload: [:stats, :search, :some_feature]
|
49
|
+
+ Rails.application.configure do
|
50
|
+
+ # Uncomment to configure which features to preload on all requests
|
51
|
+
+ # config.flipper.preload = [:stats, :search, :some_feature]
|
52
|
+
+ end
|
53
|
+
```
|
54
|
+
|
55
|
+
3. `#flipper_id`, which is used to enable features for specific actors, is now defined by [Flipper::Identifier](lib/flipper/identifier.rb) on all ActiveRecord and Sequel models. You can remove your implementation if it is in the form of `ModelName;id`.
|
56
|
+
|
57
|
+
4. When using `flipper-cloud`, The `Flipper::Cloud.app` webhook receiver is now mounted at `/_flipper` by default.
|
58
|
+
|
59
|
+
```diff
|
60
|
+
# config/routes.rb
|
61
|
+
- mount Flipper::Cloud.app, at: "/_flipper"
|
62
|
+
```
|
10
63
|
|
11
64
|
## 0.20.4
|
12
65
|
|
@@ -14,6 +67,7 @@
|
|
14
67
|
|
15
68
|
* Allow actors and time gates to deal with decimal percentages (https://github.com/jnunemaker/flipper/pull/492)
|
16
69
|
* Change Flipper::Cloud::Middleware to receive webhooks at / in addition to /webhooks.
|
70
|
+
* Add `write_through` option to ActiveSupportCacheStore adapter to support write-through caching (https://github.com/jnunemaker/flipper/pull/512)
|
17
71
|
|
18
72
|
## 0.20.3
|
19
73
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Add this line to your application's Gemfile:
|
|
21
21
|
|
22
22
|
You'll also want to pick a storage [adapter](#adapters), for example:
|
23
23
|
|
24
|
-
gem 'flipper-active_record'
|
24
|
+
gem 'flipper-active_record'
|
25
25
|
|
26
26
|
And then execute:
|
27
27
|
|
@@ -157,6 +157,7 @@ A few miscellaneous docs with more info for the hungry.
|
|
157
157
|
| pic | @mention | area |
|
158
158
|
|---|---|---|
|
159
159
|
| ![@jnunemaker](https://avatars3.githubusercontent.com/u/235?s=64) | [@jnunemaker](https://github.com/jnunemaker) | most things |
|
160
|
+
| ![@bkeepers](https://avatars3.githubusercontent.com/u/173?s=64) | [@bkeepers](https://github.com/bkeepers) | most things |
|
160
161
|
| ![@alexwheeler](https://avatars3.githubusercontent.com/u/3260042?s=64) | [@alexwheeler](https://github.com/alexwheeler) | api |
|
161
162
|
| ![@thetimbanks](https://avatars1.githubusercontent.com/u/471801?s=64) | [@thetimbanks](https://github.com/thetimbanks) | ui |
|
162
163
|
| ![@lazebny](https://avatars1.githubusercontent.com/u/6276766?s=64) | [@lazebny](https://github.com/lazebny) | docker |
|
data/docker-compose.yml
CHANGED
@@ -1,34 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
version: "2.4"
|
2
|
+
services:
|
3
|
+
# postgres:
|
4
|
+
# container_name: flipper_postgres
|
5
|
+
# image: postgres:9.4
|
6
|
+
redis:
|
7
|
+
container_name: flipper_redis
|
8
|
+
image: redis:6.2.5
|
9
|
+
mongo:
|
10
|
+
container_name: flipper_mongo
|
11
|
+
image: mongo:4.4.8
|
12
|
+
memcached:
|
13
|
+
container_name: flipper_memcached
|
14
|
+
image: memcached:1.4.33
|
15
|
+
app:
|
16
|
+
container_name: flipper_app
|
17
|
+
build:
|
18
|
+
context: .
|
19
|
+
dockerfile: Dockerfile
|
20
|
+
volumes:
|
21
|
+
- .:/srv/app
|
22
|
+
volumes_from:
|
23
|
+
- bundle_cache
|
24
|
+
links:
|
25
|
+
# - postgres
|
26
|
+
- redis
|
27
|
+
- mongo
|
28
|
+
- memcached
|
29
|
+
environment:
|
30
|
+
- REDIS_URL=redis://redis:6379
|
31
|
+
- MONGODB_HOST=mongo
|
32
|
+
- MEMCACHED_URL=memcached:11211
|
33
|
+
bundle_cache:
|
34
|
+
container_name: flipper_bundle_cache
|
35
|
+
image: busybox
|
36
|
+
volumes:
|
37
|
+
- /bundle_cache
|
data/docs/Adapters.md
CHANGED
@@ -4,18 +4,17 @@ I plan on supporting the adapters in the flipper repo. Other adapters are welcom
|
|
4
4
|
|
5
5
|
## Officially Supported
|
6
6
|
|
7
|
-
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails
|
8
|
-
* [
|
9
|
-
* [
|
10
|
-
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
|
11
|
-
* [memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
12
|
-
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta)
|
7
|
+
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails 5 and 6.
|
8
|
+
* [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
|
9
|
+
* [Redis adapter](https://github.com/jnunemaker/flipper/blob/master/docs/redis)
|
13
10
|
* [Mongo adapter](https://github.com/jnunemaker/flipper/blob/master/docs/mongo)
|
14
11
|
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
15
|
-
* [
|
16
|
-
* [
|
17
|
-
* [
|
18
|
-
* [
|
12
|
+
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http) - great for using with `Flipper::Api`
|
13
|
+
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta) - great for a variety of data stores
|
14
|
+
* [ActiveSupportCacheStore adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_support_cache_store) - great for Rails caching
|
15
|
+
* [Memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
16
|
+
* [Read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only) - great for preventing writes from production console
|
17
|
+
* [Rollout adapter](rollout/README.md) - great for switching from rollout to flipper
|
19
18
|
|
20
19
|
## Community Supported
|
21
20
|
|
data/docs/Caveats.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
# Caveats
|
2
2
|
|
3
|
-
1. The [individual actor gate](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-individual-actor) is typically not designed for hundreds or thousands of actors to be enabled. This is an explicit choice to make it easier to batch load data from the adapters instead of performing individual checks for actors over and over. If you need to enable something for more than
|
4
|
-
2. The disable method exists only to clear something that is enabled. If the thing you are disabling is not enabled, the disable is pointless. This means that if you enable one group an actor is in and disable another group, the feature will be enabled for the actor. ([related issue](https://github.com/jnunemaker/flipper/issues/71))
|
3
|
+
1. The [individual actor gate](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-individual-actor) is typically not designed for hundreds or thousands of actors to be enabled. This is an explicit choice to make it easier to batch load data from the adapters instead of performing individual checks for actors over and over. If you need to enable something for more than 100 individual actors, I would recommend using a [group](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#5-group).
|
4
|
+
2. The `disable` method exists only to clear something that is enabled. If the thing you are disabling is not enabled, the disable is pointless. This means that if you enable one group an actor is in and disable another group, the feature will be enabled for the actor. ([related issue](https://github.com/jnunemaker/flipper/issues/71))
|
data/docs/Optimization.md
CHANGED
@@ -1,52 +1,63 @@
|
|
1
1
|
# Optimization
|
2
2
|
|
3
|
-
##
|
3
|
+
## Memoization
|
4
4
|
|
5
|
-
|
5
|
+
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.
|
6
6
|
|
7
|
-
|
7
|
+
### Preloading
|
8
|
+
|
9
|
+
Flipper will preload all features before each request by default, which is recommended if you have a limited number of features (< 100?) and they are used on most requests. If you have a lot of features, but only a few are used on most requests, you may want to customize preloading:
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# config/initializers/flipper.rb
|
13
|
+
Rails.application.configure do
|
14
|
+
# Load specific features that are used on most requests
|
15
|
+
config.flipper.preload = [:stats, :search, :some_feature]
|
16
|
+
|
17
|
+
# Or completely disable preloading
|
18
|
+
config.flipper.preload = false
|
15
19
|
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Features that are not preloaded are still memoized, ensuring one adapter call per feature during a request.
|
23
|
+
|
24
|
+
### Skip memoization
|
25
|
+
|
26
|
+
Prevent preloading and memoization on specific requests by setting `memoize` to a proc that evaluates to false.
|
16
27
|
|
17
|
-
|
18
|
-
|
28
|
+
```ruby
|
29
|
+
# config/initializers/flipper.rb
|
30
|
+
Rails.application.configure do
|
31
|
+
config.flipper.memoize = ->(request) { !request.path.start_with?("/assets") }
|
32
|
+
end
|
19
33
|
```
|
20
34
|
|
21
|
-
|
35
|
+
### Disable memoization
|
22
36
|
|
23
|
-
|
37
|
+
To disable memoization entirely:
|
24
38
|
|
25
39
|
```ruby
|
26
|
-
Rails.
|
27
|
-
|
40
|
+
Rails.application.configure do
|
41
|
+
config.flipper.memoize = false
|
42
|
+
end
|
28
43
|
```
|
29
44
|
|
30
|
-
###
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# skip preloading and memoizing if path starts with /assets
|
47
|
-
Rails.configuration.middleware.use Flipper::Middleware::Memoizer,
|
48
|
-
unless: ->(request) { request.path.start_with?("/assets") }
|
49
|
-
```
|
45
|
+
### Advanced
|
46
|
+
|
47
|
+
Memoization is implemented as a Rack middleware, which can be used manually in any Ruby app:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
use Flipper::Middleware::Memoizer,
|
51
|
+
preload: true,
|
52
|
+
unless: ->(request) { request.path.start_with?("/assets") }
|
53
|
+
```
|
54
|
+
|
55
|
+
**Also Note**: If you need to customize the instance of Flipper used by the memoizer, you can pass the instance to `SetupEnv`:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
use Flipper::Middleware::SetupEnv, -> { Flipper.new(...) }
|
59
|
+
use Flipper::Middleware::Memoizer
|
60
|
+
```
|
50
61
|
|
51
62
|
## Cache Adapters
|
52
63
|
|
@@ -61,11 +72,15 @@ https://github.com/petergoldstein/dalli
|
|
61
72
|
Example using the Dalli cache adapter with the Memory adapter and a TTL of 600 seconds:
|
62
73
|
|
63
74
|
```ruby
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
75
|
+
Flipper.configure do |config|
|
76
|
+
config.adapter do
|
77
|
+
dalli = Dalli::Client.new('localhost:11211')
|
78
|
+
adapter = Flipper::Adapters::Memory.new
|
79
|
+
Flipper::Adapters::Dalli.new(adapter, dalli, 600)
|
80
|
+
end
|
81
|
+
end
|
68
82
|
```
|
83
|
+
|
69
84
|
### RedisCache
|
70
85
|
|
71
86
|
Applications using [Redis](https://redis.io/) via the [redis-rb](https://github.com/redis/redis-rb) client can take advantage of the RedisCache adapter.
|
@@ -75,12 +90,15 @@ Initialize `RedisCache` with a flipper [adapter](https://github.com/jnunemaker/
|
|
75
90
|
Example using the RedisCache adapter with the Memory adapter and a TTL of 4800 seconds:
|
76
91
|
|
77
92
|
```ruby
|
78
|
-
|
93
|
+
require 'flipper/adapters/redis_cache'
|
79
94
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
95
|
+
Flipper.configure do |config|
|
96
|
+
config.adapter do
|
97
|
+
redis = Redis.new(url: ENV['REDIS_URL'])
|
98
|
+
memory_adapter = Flipper::Adapters::Memory.new
|
99
|
+
Flipper::Adapters::RedisCache.new(memory_adapter, redis, 4800)
|
100
|
+
end
|
101
|
+
end
|
84
102
|
```
|
85
103
|
|
86
104
|
### ActiveSupportCacheStore
|
@@ -105,10 +123,15 @@ Example using the ActiveSupportCacheStore adapter with ActiveSupport's [MemorySt
|
|
105
123
|
require 'active_support/cache'
|
106
124
|
require 'flipper/adapters/active_support_cache_store'
|
107
125
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
126
|
+
Flipper.configure do |config|
|
127
|
+
config.adapter do
|
128
|
+
Flipper::Adapters::ActiveSupportCacheStore.new(
|
129
|
+
Flipper::Adapters::Memory.new,
|
130
|
+
ActiveSupport::Cache::MemoryStore.new # Or Rails.cache,
|
131
|
+
expires_in: 5.minutes
|
132
|
+
)
|
133
|
+
end
|
134
|
+
end
|
112
135
|
```
|
113
136
|
|
114
137
|
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.
|