flipper-dalli 0.10.1 → 0.10.2
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 +35 -5
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/dalli_spec.rb +28 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef5a0f642bcfcb0213304e46a573ed943a54fec6
|
4
|
+
data.tar.gz: a80ffc852ed4bb0ed5b239ba34292b03aa1b74b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 108cc70cbffdd6790ee1a599e1e34b0533ff47e24146eb8e12bd1f6d87174276be2aceca00b8ddd2fd4c374923a3901353f466419a2190cb1f140b799fa9f6bd
|
7
|
+
data.tar.gz: 1cf97e8949eeca88b5608aeddffa4e315992e86b8ae48270ce26ea963c562b04b7449415e640b495fb70021a9d455214c67a80e3e89f77513ce5dc5f4f89a87d
|
@@ -7,7 +7,14 @@ module Flipper
|
|
7
7
|
class Dalli
|
8
8
|
include ::Flipper::Adapter
|
9
9
|
|
10
|
-
|
10
|
+
Version = "v1".freeze
|
11
|
+
Namespace = "flipper/#{Version}".freeze
|
12
|
+
FeaturesKey = "#{Namespace}/features".freeze
|
13
|
+
|
14
|
+
# Private
|
15
|
+
def self.key_for(key)
|
16
|
+
"#{Namespace}/feature/#{key}"
|
17
|
+
end
|
11
18
|
|
12
19
|
# Internal
|
13
20
|
attr_reader :cache
|
@@ -41,36 +48,59 @@ module Flipper
|
|
41
48
|
def remove(feature)
|
42
49
|
result = @adapter.remove(feature)
|
43
50
|
@cache.delete(FeaturesKey)
|
51
|
+
@cache.delete(key_for(feature.key))
|
44
52
|
result
|
45
53
|
end
|
46
54
|
|
47
55
|
# Public
|
48
56
|
def clear(feature)
|
49
57
|
result = @adapter.clear(feature)
|
50
|
-
@cache.delete(feature)
|
58
|
+
@cache.delete(key_for(feature.key))
|
51
59
|
result
|
52
60
|
end
|
53
61
|
|
54
62
|
# Public
|
55
63
|
def get(feature)
|
56
|
-
@cache.fetch(feature, @ttl) do
|
64
|
+
@cache.fetch(key_for(feature.key), @ttl) do
|
57
65
|
@adapter.get(feature)
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
69
|
+
def get_multi(features)
|
70
|
+
keys = features.map { |feature| key_for(feature.key) }
|
71
|
+
result = @cache.get_multi(keys)
|
72
|
+
uncached_features = features.reject { |feature| result[key_for(feature.key)] }
|
73
|
+
|
74
|
+
if uncached_features.any?
|
75
|
+
response = @adapter.get_multi(uncached_features)
|
76
|
+
response.each do |key, value|
|
77
|
+
@cache.set(key_for(key), value, @ttl)
|
78
|
+
result[key] = value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
61
85
|
# Public
|
62
86
|
def enable(feature, gate, thing)
|
63
87
|
result = @adapter.enable(feature, gate, thing)
|
64
|
-
@cache.delete(feature)
|
88
|
+
@cache.delete(key_for(feature.key))
|
65
89
|
result
|
66
90
|
end
|
67
91
|
|
68
92
|
# Public
|
69
93
|
def disable(feature, gate, thing)
|
70
94
|
result = @adapter.disable(feature, gate, thing)
|
71
|
-
@cache.delete(feature)
|
95
|
+
@cache.delete(key_for(feature.key))
|
72
96
|
result
|
73
97
|
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def key_for(key)
|
102
|
+
self.class.key_for(key)
|
103
|
+
end
|
74
104
|
end
|
75
105
|
end
|
76
106
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -17,6 +17,34 @@ RSpec.describe Flipper::Adapters::Dalli do
|
|
17
17
|
|
18
18
|
it_should_behave_like 'a flipper adapter'
|
19
19
|
|
20
|
+
describe "#remove" do
|
21
|
+
it "expires feature" do
|
22
|
+
feature = flipper[:stats]
|
23
|
+
adapter.get(feature)
|
24
|
+
adapter.remove(feature)
|
25
|
+
expect(cache.get(described_class.key_for(feature))).to be(nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#get_multi" do
|
30
|
+
it "warms uncached features" do
|
31
|
+
stats = flipper[:stats]
|
32
|
+
search = flipper[:search]
|
33
|
+
other = flipper[:other]
|
34
|
+
stats.enable
|
35
|
+
search.enable
|
36
|
+
|
37
|
+
adapter.get(stats)
|
38
|
+
expect(cache.get(described_class.key_for(search))).to be(nil)
|
39
|
+
expect(cache.get(described_class.key_for(other))).to be(nil)
|
40
|
+
|
41
|
+
adapter.get_multi([stats, search, other])
|
42
|
+
|
43
|
+
expect(cache.get(described_class.key_for(search))[:boolean]).to eq("true")
|
44
|
+
expect(cache.get(described_class.key_for(other))[:boolean]).to be(nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
20
48
|
describe "#name" do
|
21
49
|
it "is dalli" do
|
22
50
|
expect(subject.name).to be(:dalli)
|
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: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-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: 0.10.
|
19
|
+
version: 0.10.2
|
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.10.
|
26
|
+
version: 0.10.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dalli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|