flipper-active_support_cache_store 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ef54c96a5931fdee8bdeedffa0e6eee6f66c0163a463a0286157a2b3be9ddc
|
4
|
+
data.tar.gz: fa00f5dbcf917275ef8f675396487e1d5404f85b5c884de7aed9f3d15d3228d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a150b0fc8ab3366f832c77388eaf2e70e3ac11576e19f77c7c8fe7212113a9c9393399c5cd1abe2d4ee81a0156033202a2ed42412981d0fbe96dbedc345870c5
|
7
|
+
data.tar.gz: 739e96d8c2d3558a90a58eca3520f1654ddf91343f0202fc764ed1dcfbf968d56179549ec10374fdfd29320f7541df283552234cec41613df5213fe03653cc65
|
@@ -9,30 +9,21 @@ module Flipper
|
|
9
9
|
class ActiveSupportCacheStore
|
10
10
|
include ::Flipper::Adapter
|
11
11
|
|
12
|
-
Version = 'v1'.freeze
|
13
|
-
Namespace = "flipper/#{Version}".freeze
|
14
|
-
FeaturesKey = "#{Namespace}/features".freeze
|
15
|
-
GetAllKey = "#{Namespace}/get_all".freeze
|
16
|
-
|
17
|
-
# Private
|
18
|
-
def self.key_for(key)
|
19
|
-
"#{Namespace}/feature/#{key}"
|
20
|
-
end
|
21
|
-
|
22
12
|
# Internal
|
23
13
|
attr_reader :cache
|
24
14
|
|
25
|
-
# Public: The name of the adapter.
|
26
|
-
attr_reader :name
|
27
|
-
|
28
15
|
# Public
|
29
16
|
def initialize(adapter, cache, expires_in: nil, write_through: false)
|
30
17
|
@adapter = adapter
|
31
|
-
@name = :active_support_cache_store
|
32
18
|
@cache = cache
|
33
19
|
@write_options = {}
|
34
20
|
@write_options[:expires_in] = expires_in if expires_in
|
35
21
|
@write_through = write_through
|
22
|
+
|
23
|
+
@cache_version = 'v1'.freeze
|
24
|
+
@namespace = "flipper/#{@cache_version}".freeze
|
25
|
+
@features_key = "#{@namespace}/features".freeze
|
26
|
+
@get_all_key = "#{@namespace}/get_all".freeze
|
36
27
|
end
|
37
28
|
|
38
29
|
# Public
|
@@ -43,14 +34,14 @@ module Flipper
|
|
43
34
|
# Public
|
44
35
|
def add(feature)
|
45
36
|
result = @adapter.add(feature)
|
46
|
-
@cache.delete(
|
37
|
+
@cache.delete(@features_key)
|
47
38
|
result
|
48
39
|
end
|
49
40
|
|
50
41
|
## Public
|
51
42
|
def remove(feature)
|
52
43
|
result = @adapter.remove(feature)
|
53
|
-
@cache.delete(
|
44
|
+
@cache.delete(@features_key)
|
54
45
|
|
55
46
|
if @write_through
|
56
47
|
@cache.write(key_for(feature.key), default_config, @write_options)
|
@@ -80,12 +71,12 @@ module Flipper
|
|
80
71
|
end
|
81
72
|
|
82
73
|
def get_all
|
83
|
-
if @cache.write(
|
74
|
+
if @cache.write(@get_all_key, Time.now.to_i, @write_options.merge(unless_exist: true))
|
84
75
|
response = @adapter.get_all
|
85
76
|
response.each do |key, value|
|
86
77
|
@cache.write(key_for(key), value, @write_options)
|
87
78
|
end
|
88
|
-
@cache.write(
|
79
|
+
@cache.write(@features_key, response.keys.to_set, @write_options)
|
89
80
|
response
|
90
81
|
else
|
91
82
|
features = read_feature_keys.map { |key| Flipper::Feature.new(key, self) }
|
@@ -122,12 +113,12 @@ module Flipper
|
|
122
113
|
private
|
123
114
|
|
124
115
|
def key_for(key)
|
125
|
-
|
116
|
+
"#{@namespace}/feature/#{key}"
|
126
117
|
end
|
127
118
|
|
128
119
|
# Internal: Returns an array of the known feature keys.
|
129
120
|
def read_feature_keys
|
130
|
-
@cache.fetch(
|
121
|
+
@cache.fetch(@features_key, @write_options) { @adapter.features }
|
131
122
|
end
|
132
123
|
|
133
124
|
# Internal: Given an array of features, attempts to read through cache in
|
data/lib/flipper/version.rb
CHANGED
@@ -28,8 +28,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'expires feature and deletes the cache' do
|
31
|
-
expect(cache.read(
|
32
|
-
expect(cache.exist?(
|
31
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to be_nil
|
32
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(false)
|
33
33
|
expect(feature).not_to be_enabled
|
34
34
|
end
|
35
35
|
|
@@ -37,8 +37,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
37
37
|
let(:write_through) { true }
|
38
38
|
|
39
39
|
it 'expires feature and writes an empty value to the cache' do
|
40
|
-
expect(cache.read(
|
41
|
-
expect(cache.exist?(
|
40
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to eq(adapter.default_config)
|
41
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(true)
|
42
42
|
expect(feature).not_to be_enabled
|
43
43
|
end
|
44
44
|
end
|
@@ -52,8 +52,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'enables feature and deletes the cache' do
|
55
|
-
expect(cache.read(
|
56
|
-
expect(cache.exist?(
|
55
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to be_nil
|
56
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(false)
|
57
57
|
expect(feature).to be_enabled
|
58
58
|
end
|
59
59
|
|
@@ -61,8 +61,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
61
61
|
let(:write_through) { true }
|
62
62
|
|
63
63
|
it 'expires feature and writes to the cache' do
|
64
|
-
expect(cache.exist?(
|
65
|
-
expect(cache.read(
|
64
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(true)
|
65
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to include(boolean: 'true')
|
66
66
|
expect(feature).to be_enabled
|
67
67
|
end
|
68
68
|
end
|
@@ -76,8 +76,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'disables feature and deletes the cache' do
|
79
|
-
expect(cache.read(
|
80
|
-
expect(cache.exist?(
|
79
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to be_nil
|
80
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(false)
|
81
81
|
expect(feature).not_to be_enabled
|
82
82
|
end
|
83
83
|
|
@@ -85,8 +85,8 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
85
85
|
let(:write_through) { true }
|
86
86
|
|
87
87
|
it 'expires feature and writes to the cache' do
|
88
|
-
expect(cache.exist?(
|
89
|
-
expect(cache.read(
|
88
|
+
expect(cache.exist?("flipper/v1/feature/#{feature.key}")).to be(true)
|
89
|
+
expect(cache.read("flipper/v1/feature/#{feature.key}")).to include(boolean: nil)
|
90
90
|
expect(feature).not_to be_enabled
|
91
91
|
end
|
92
92
|
end
|
@@ -103,13 +103,13 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
103
103
|
memory_adapter.reset
|
104
104
|
|
105
105
|
adapter.get(stats)
|
106
|
-
expect(cache.read(
|
107
|
-
expect(cache.read(
|
106
|
+
expect(cache.read("flipper/v1/feature/#{search.key}")).to be(nil)
|
107
|
+
expect(cache.read("flipper/v1/feature/#{other.key}")).to be(nil)
|
108
108
|
|
109
109
|
adapter.get_multi([stats, search, other])
|
110
110
|
|
111
|
-
expect(cache.read(
|
112
|
-
expect(cache.read(
|
111
|
+
expect(cache.read("flipper/v1/feature/#{search.key}")[:boolean]).to eq('true')
|
112
|
+
expect(cache.read("flipper/v1/feature/#{other.key}")[:boolean]).to be(nil)
|
113
113
|
|
114
114
|
adapter.get_multi([stats, search, other])
|
115
115
|
adapter.get_multi([stats, search, other])
|
@@ -128,9 +128,9 @@ RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do
|
|
128
128
|
|
129
129
|
it 'warms all features' do
|
130
130
|
adapter.get_all
|
131
|
-
expect(cache.read(
|
132
|
-
expect(cache.read(
|
133
|
-
expect(cache.read(
|
131
|
+
expect(cache.read("flipper/v1/feature/#{stats.key}")[:boolean]).to eq('true')
|
132
|
+
expect(cache.read("flipper/v1/feature/#{search.key}")[:boolean]).to be(nil)
|
133
|
+
expect(cache.read("flipper/v1/get_all")).to be_within(2).of(Time.now.to_i)
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'returns same result when already cached' do
|
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: 1.
|
4
|
+
version: 1.1.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: 2023-08
|
11
|
+
date: 2023-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.1.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: 1.
|
26
|
+
version: 1.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|