flipper-dalli 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 +4 -4
- data/lib/flipper/adapters/dalli.rb +11 -20
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/dalli_spec.rb +8 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ab7d84ca0cfcde7d80882fde5f30a65352291b9922e5fd19d6aa86ae360214f
|
4
|
+
data.tar.gz: 0eb5ae0eb3b124b16b6995a292554c1a7af72e0605036fad24066d8e8a9ef983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9da38d17e220fc3924e1b7be24db7680a8bc85ccda6c759f1658942d001250336a67db362f0860b3706367569d29e16b22a5162bfb85693df8d867115cf7ff55
|
7
|
+
data.tar.gz: 1aeb61c9b9217dcc366342a4a7ce411992c2bd076ccab2238086ca1c7bf6df89f89cca07885f70364cda4490407e25bdee783a2a55212d94346a8c8b039a0f52
|
@@ -8,31 +8,22 @@ module Flipper
|
|
8
8
|
class Dalli
|
9
9
|
include ::Flipper::Adapter
|
10
10
|
|
11
|
-
Version = 'v1'.freeze
|
12
|
-
Namespace = "flipper/#{Version}".freeze
|
13
|
-
FeaturesKey = "#{Namespace}/features".freeze
|
14
|
-
GetAllKey = "#{Namespace}/get_all".freeze
|
15
|
-
|
16
|
-
# Private
|
17
|
-
def self.key_for(key)
|
18
|
-
"#{Namespace}/feature/#{key}"
|
19
|
-
end
|
20
|
-
|
21
11
|
# Internal
|
22
12
|
attr_reader :cache
|
23
13
|
|
24
|
-
# Public: The name of the adapter.
|
25
|
-
attr_reader :name
|
26
|
-
|
27
14
|
# Public: The ttl for all cached data.
|
28
15
|
attr_reader :ttl
|
29
16
|
|
30
17
|
# Public
|
31
18
|
def initialize(adapter, cache, ttl = 0)
|
32
19
|
@adapter = adapter
|
33
|
-
@name = :dalli
|
34
20
|
@cache = cache
|
35
21
|
@ttl = ttl
|
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
|
@cache.delete(key_for(feature.key))
|
55
46
|
result
|
56
47
|
end
|
@@ -74,12 +65,12 @@ module Flipper
|
|
74
65
|
end
|
75
66
|
|
76
67
|
def get_all
|
77
|
-
if @cache.add(
|
68
|
+
if @cache.add(@get_all_key, Time.now.to_i, @ttl)
|
78
69
|
response = @adapter.get_all
|
79
70
|
response.each do |key, value|
|
80
71
|
@cache.set(key_for(key), value, @ttl)
|
81
72
|
end
|
82
|
-
@cache.set(
|
73
|
+
@cache.set(@features_key, response.keys.to_set, @ttl)
|
83
74
|
response
|
84
75
|
else
|
85
76
|
features = read_feature_keys.map { |key| Flipper::Feature.new(key, self) }
|
@@ -104,11 +95,11 @@ module Flipper
|
|
104
95
|
private
|
105
96
|
|
106
97
|
def key_for(key)
|
107
|
-
|
98
|
+
"#{@namespace}/feature/#{key}"
|
108
99
|
end
|
109
100
|
|
110
101
|
def read_feature_keys
|
111
|
-
@cache.fetch(
|
102
|
+
@cache.fetch(@features_key, @ttl) { @adapter.features }
|
112
103
|
end
|
113
104
|
|
114
105
|
# Internal: Given an array of features, attempts to read through cache in
|
data/lib/flipper/version.rb
CHANGED
@@ -26,7 +26,7 @@ RSpec.describe Flipper::Adapters::Dalli do
|
|
26
26
|
feature = flipper[:stats]
|
27
27
|
adapter.get(feature)
|
28
28
|
adapter.remove(feature)
|
29
|
-
expect(cache.get(
|
29
|
+
expect(cache.get("flipper/v1/#{feature.key}")).to be(nil)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -41,13 +41,13 @@ RSpec.describe Flipper::Adapters::Dalli do
|
|
41
41
|
memory_adapter.reset
|
42
42
|
|
43
43
|
adapter.get(stats)
|
44
|
-
expect(cache.get(
|
45
|
-
expect(cache.get(
|
44
|
+
expect(cache.get("flipper/v1/feature/#{search.key}")).to be(nil)
|
45
|
+
expect(cache.get("flipper/v1/feature/#{other.key}")).to be(nil)
|
46
46
|
|
47
47
|
adapter.get_multi([stats, search, other])
|
48
48
|
|
49
|
-
expect(cache.get(
|
50
|
-
expect(cache.get(
|
49
|
+
expect(cache.get("flipper/v1/feature/#{search.key}")[:boolean]).to eq('true')
|
50
|
+
expect(cache.get("flipper/v1/feature/#{other.key}")[:boolean]).to be(nil)
|
51
51
|
|
52
52
|
adapter.get_multi([stats, search, other])
|
53
53
|
adapter.get_multi([stats, search, other])
|
@@ -66,9 +66,9 @@ RSpec.describe Flipper::Adapters::Dalli do
|
|
66
66
|
|
67
67
|
it 'warms all features' do
|
68
68
|
adapter.get_all
|
69
|
-
expect(cache.get(
|
70
|
-
expect(cache.get(
|
71
|
-
expect(cache.get(
|
69
|
+
expect(cache.get("flipper/v1/feature/#{stats.key}")[:boolean]).to eq('true')
|
70
|
+
expect(cache.get("flipper/v1/feature/#{search.key}")[:boolean]).to be(nil)
|
71
|
+
expect(cache.get("flipper/v1/get_all")).to be_within(2).of(Time.now.to_i)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'returns same result when already cached' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-dalli
|
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: dalli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|