flipper-active_support_cache_store 0.20.3 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/active_support_cache_store/README.md +10 -4
- data/flipper-active_support_cache_store.gemspec +1 -1
- data/lib/flipper/adapters/active_support_cache_store.rb +23 -4
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/active_support_cache_store_spec.rb +70 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b46bca885969a63c770a433abd9cd199d8b86a6d1827644a52885418ae5f0c6
|
4
|
+
data.tar.gz: 36638d200625fd6dd18aa5e0dbb87fddb53fe93efda554b7589c2834b2640e0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d0b91e2e7e284f477e5c01013498966f8fe8bbc0a8c70205bc6590c0b8e9eeba74bedd918f0601217ff2f460f25f499afda3044998d3af65c340c265af0030
|
7
|
+
data.tar.gz: 1dd720b06aa8b06fcbaaa4b0e8da8c403d9821320dc50b3cee70f1be231a33539991b85b131fc72b06685096744d3431b63c9369269c5951323790467b055a0f
|
@@ -22,11 +22,17 @@ Or install it yourself with:
|
|
22
22
|
require 'active_support/cache'
|
23
23
|
require 'flipper/adapters/active_support_cache_store'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
Flipper.configure do |config|
|
26
|
+
config.adapter do
|
27
|
+
Flipper::Adapters::ActiveSupportCacheStore.new(
|
28
|
+
Flipper::Adapters::Memory.new,
|
29
|
+
ActiveSupport::Cache::MemoryStore.new, # Or Rails.cache
|
30
|
+
expires_in: 5.minutes
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
29
34
|
```
|
35
|
+
|
30
36
|
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.
|
31
37
|
|
32
38
|
## Internals
|
@@ -25,12 +25,13 @@ module Flipper
|
|
25
25
|
attr_reader :name
|
26
26
|
|
27
27
|
# Public
|
28
|
-
def initialize(adapter, cache, expires_in: nil)
|
28
|
+
def initialize(adapter, cache, expires_in: nil, write_through: false)
|
29
29
|
@adapter = adapter
|
30
30
|
@name = :active_support_cache_store
|
31
31
|
@cache = cache
|
32
32
|
@write_options = {}
|
33
33
|
@write_options[:expires_in] = expires_in if expires_in
|
34
|
+
@write_through = write_through
|
34
35
|
end
|
35
36
|
|
36
37
|
# Public
|
@@ -49,7 +50,13 @@ module Flipper
|
|
49
50
|
def remove(feature)
|
50
51
|
result = @adapter.remove(feature)
|
51
52
|
@cache.delete(FeaturesKey)
|
52
|
-
|
53
|
+
|
54
|
+
if @write_through
|
55
|
+
@cache.write(key_for(feature.key), default_config, @write_options)
|
56
|
+
else
|
57
|
+
@cache.delete(key_for(feature.key))
|
58
|
+
end
|
59
|
+
|
53
60
|
result
|
54
61
|
end
|
55
62
|
|
@@ -88,14 +95,26 @@ module Flipper
|
|
88
95
|
## Public
|
89
96
|
def enable(feature, gate, thing)
|
90
97
|
result = @adapter.enable(feature, gate, thing)
|
91
|
-
|
98
|
+
|
99
|
+
if @write_through
|
100
|
+
@cache.write(key_for(feature.key), @adapter.get(feature), @write_options)
|
101
|
+
else
|
102
|
+
@cache.delete(key_for(feature.key))
|
103
|
+
end
|
104
|
+
|
92
105
|
result
|
93
106
|
end
|
94
107
|
|
95
108
|
## Public
|
96
109
|
def disable(feature, gate, thing)
|
97
110
|
result = @adapter.disable(feature, gate, thing)
|
98
|
-
|
111
|
+
|
112
|
+
if @write_through
|
113
|
+
@cache.write(key_for(feature.key), @adapter.get(feature), @write_options)
|
114
|
+
else
|
115
|
+
@cache.delete(key_for(feature.key))
|
116
|
+
end
|
117
|
+
|
99
118
|
result
|
100
119
|
end
|
101
120
|
|
data/lib/flipper/version.rb
CHANGED
@@ -9,8 +9,9 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
9
9
|
let(:memory_adapter) do
|
10
10
|
Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new)
|
11
11
|
end
|
12
|
-
let(:cache) { ActiveSupport::Cache::
|
13
|
-
let(:
|
12
|
+
let(:cache) { ActiveSupport::Cache::MemoryStore.new }
|
13
|
+
let(:write_through) { false }
|
14
|
+
let(:adapter) { described_class.new(memory_adapter, cache, expires_in: 10.seconds, write_through: write_through) }
|
14
15
|
let(:flipper) { Flipper.new(adapter) }
|
15
16
|
|
16
17
|
subject { adapter }
|
@@ -22,11 +23,75 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
22
23
|
it_should_behave_like 'a flipper adapter'
|
23
24
|
|
24
25
|
describe '#remove' do
|
25
|
-
|
26
|
-
|
26
|
+
let(:feature) { flipper[:stats] }
|
27
|
+
|
28
|
+
before do
|
27
29
|
adapter.get(feature)
|
28
30
|
adapter.remove(feature)
|
29
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'expires feature and deletes the cache' do
|
34
|
+
expect(cache.read(described_class.key_for(feature))).to be_nil
|
35
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(false)
|
36
|
+
expect(feature).not_to be_enabled
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with write-through caching' do
|
40
|
+
let(:write_through) { true }
|
41
|
+
|
42
|
+
it 'expires feature and writes an empty value to the cache' do
|
43
|
+
expect(cache.read(described_class.key_for(feature))).to eq(adapter.default_config)
|
44
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(true)
|
45
|
+
expect(feature).not_to be_enabled
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#enable' do
|
51
|
+
let(:feature) { flipper[:stats] }
|
52
|
+
|
53
|
+
before do
|
54
|
+
adapter.enable(feature, feature.gate(:boolean), flipper.boolean)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'enables feature and deletes the cache' do
|
58
|
+
expect(cache.read(described_class.key_for(feature))).to be_nil
|
59
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(false)
|
60
|
+
expect(feature).to be_enabled
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with write-through caching' do
|
64
|
+
let(:write_through) { true }
|
65
|
+
|
66
|
+
it 'expires feature and writes to the cache' do
|
67
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(true)
|
68
|
+
expect(cache.read(described_class.key_for(feature))).to include(boolean: 'true')
|
69
|
+
expect(feature).to be_enabled
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#disable' do
|
75
|
+
let(:feature) { flipper[:stats] }
|
76
|
+
|
77
|
+
before do
|
78
|
+
adapter.disable(feature, feature.gate(:boolean), flipper.boolean)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'disables feature and deletes the cache' do
|
82
|
+
expect(cache.read(described_class.key_for(feature))).to be_nil
|
83
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(false)
|
84
|
+
expect(feature).not_to be_enabled
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with write-through caching' do
|
88
|
+
let(:write_through) { true }
|
89
|
+
|
90
|
+
it 'expires feature and writes to the cache' do
|
91
|
+
expect(cache.exist?(described_class.key_for(feature))).to be(true)
|
92
|
+
expect(cache.read(described_class.key_for(feature))).to include(boolean: nil)
|
93
|
+
expect(feature).not_to be_enabled
|
94
|
+
end
|
30
95
|
end
|
31
96
|
end
|
32
97
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-active_support_cache_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,21 +16,21 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.22.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.22.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '7'
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '4.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '7'
|