flipper-active_support_cache_store 1.0.0 → 1.1.1
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: ac9ee92d7812cb26cb22b17a3927bfdd9be5ee24525333520f59fc244c04df71
|
4
|
+
data.tar.gz: 6fd4095421cc78c9141a694958a59eb0b1f89efcb0226768219290fb0bf6b1ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b1984561fc79e70e3dc38615903014ee327a81614c97a6d7dfef4ffadc9d19c7477c66a8b44b029042a5345acca3126d77324941fee446ba60e3cbc2124239
|
7
|
+
data.tar.gz: '088af52428c6ec6c44f6bc5a2bd1d3f10772c859587fd8ca158a740fc14b56bb0765dcc7d3680dbf3271ec9f318340f55852ac1df64b2e41d9120e80d24e17c9'
|
@@ -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.1
|
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-
|
11
|
+
date: 2023-12-09 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.1
|
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.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|