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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 663526b8a3f866ac7150affe4d0ccc3882a8d135929622b1631dbcf36f5f91a9
4
- data.tar.gz: b9d80d481fd319d86b24acca3170a5ef28156401287b9ceaa59a5001af4603e0
3
+ metadata.gz: 5ab7d84ca0cfcde7d80882fde5f30a65352291b9922e5fd19d6aa86ae360214f
4
+ data.tar.gz: 0eb5ae0eb3b124b16b6995a292554c1a7af72e0605036fad24066d8e8a9ef983
5
5
  SHA512:
6
- metadata.gz: af43b94ce3effeb2ff64e86fb64bdd21374ffebcb708c6e284928299c3ed46ee77e8d0ed3d78c2226700e65746cb6cf84817dfa4bb2bb534a4bfb9124e5cadca
7
- data.tar.gz: 623a1164e98aaff4aaf41db86a354fbd141b2571677e945d5e441d83d03167e17b9a4b92d15e7c742c852d8e5134e681440382886795018c95aecd1fd1ec9fcc
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(FeaturesKey)
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(FeaturesKey)
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(GetAllKey, Time.now.to_i, @ttl)
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(FeaturesKey, response.keys.to_set, @ttl)
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
- self.class.key_for(key)
98
+ "#{@namespace}/feature/#{key}"
108
99
  end
109
100
 
110
101
  def read_feature_keys
111
- @cache.fetch(FeaturesKey, @ttl) { @adapter.features }
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
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -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(described_class.key_for(feature))).to be(nil)
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(described_class.key_for(search))).to be(nil)
45
- expect(cache.get(described_class.key_for(other))).to be(nil)
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(described_class.key_for(search))[:boolean]).to eq('true')
50
- expect(cache.get(described_class.key_for(other))[:boolean]).to be(nil)
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(described_class.key_for(stats))[:boolean]).to eq('true')
70
- expect(cache.get(described_class.key_for(search))[:boolean]).to be(nil)
71
- expect(cache.get(described_class::GetAllKey)).to be_within(2).of(Time.now.to_i)
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.0.0
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-23 00:00:00.000000000 Z
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.0.0
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.0.0
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dalli
29
29
  requirement: !ruby/object:Gem::Requirement