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: 4af9c24a757e7b8a54a0aeb46b2ab060e7800c8d8c38c90daff37b046a0c3a13
4
- data.tar.gz: dadc9bba7b9be524803b436548dd4cb1e67dac3ee3b8ea1b6f3bc53c58ebd980
3
+ metadata.gz: ac9ee92d7812cb26cb22b17a3927bfdd9be5ee24525333520f59fc244c04df71
4
+ data.tar.gz: 6fd4095421cc78c9141a694958a59eb0b1f89efcb0226768219290fb0bf6b1ac
5
5
  SHA512:
6
- metadata.gz: 05f3321be57b5faf88b94bdde97c04d6716524b87947661a989d51c840f1437f8ba75e68ba86828bd582d66de4c3bf612e18dbaef72a7baef37cb92a2e0edcbd
7
- data.tar.gz: 22e35550741299a38bba9867baec0915b293d5b93f78a4dba1696c374d8c87390c5a71ebb2b3f558dba2a72bf7c30b31c39125ae23f28e6dee23bdb7af94ff42
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(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
 
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(GetAllKey, Time.now.to_i, @write_options.merge(unless_exist: true))
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(FeaturesKey, response.keys.to_set, @write_options)
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
- self.class.key_for(key)
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(FeaturesKey, @write_options) { @adapter.features }
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
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
@@ -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(described_class.key_for(feature))).to be_nil
32
- expect(cache.exist?(described_class.key_for(feature))).to be(false)
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(described_class.key_for(feature))).to eq(adapter.default_config)
41
- expect(cache.exist?(described_class.key_for(feature))).to be(true)
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(described_class.key_for(feature))).to be_nil
56
- expect(cache.exist?(described_class.key_for(feature))).to be(false)
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?(described_class.key_for(feature))).to be(true)
65
- expect(cache.read(described_class.key_for(feature))).to include(boolean: 'true')
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(described_class.key_for(feature))).to be_nil
80
- expect(cache.exist?(described_class.key_for(feature))).to be(false)
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?(described_class.key_for(feature))).to be(true)
89
- expect(cache.read(described_class.key_for(feature))).to include(boolean: nil)
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(described_class.key_for(search))).to be(nil)
107
- expect(cache.read(described_class.key_for(other))).to be(nil)
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(described_class.key_for(search))[:boolean]).to eq('true')
112
- expect(cache.read(described_class.key_for(other))[:boolean]).to be(nil)
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(described_class.key_for(stats))[:boolean]).to eq('true')
132
- expect(cache.read(described_class.key_for(search))[:boolean]).to be(nil)
133
- expect(cache.read(described_class::GetAllKey)).to be_within(2).of(Time.now.to_i)
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.0.0
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-08-23 00:00:00.000000000 Z
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.0.0
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.0.0
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement