atomic_cache 0.2.0.rc1 → 0.2.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/atomic_cache/concerns/global_lmt_cache_concern.rb +1 -1
- data/lib/atomic_cache/key/keyspace.rb +4 -4
- data/lib/atomic_cache/version.rb +1 -1
- data/spec/atomic_cache/concerns/global_lmt_cache_concern_spec.rb +7 -0
- data/spec/atomic_cache/key/keyspace_spec.rb +34 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d908f524b778436fea47a5a576f1f64003d6640ff734ce61aa711d4432fb2cac
|
4
|
+
data.tar.gz: 7fa480b5bd764c4f4b5e2d6a940e42fbccc4900bd892e8a6578d76389cafc09d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19a87c2ef28d260290edf004559611228cbf79d378814db31d6d1ffb24399b118bdff8c66d3049ae7c8f028039b5606b1abe80d72726406eae759c301639a4d4
|
7
|
+
data.tar.gz: e18ea892a4eb44e0fb851d0e5aae5aa81adf2443507e8dd4e2c9273342759db1d277f27a00444dd9e8b970783927481c60f1c67c08d1639af7f7139e09679be1
|
@@ -20,11 +20,11 @@ module AtomicCache
|
|
20
20
|
# @param separator [String] character or string to separate keyspace segments
|
21
21
|
# @param timestamp_formatter [Proc] function to turn Time -> String
|
22
22
|
def initialize(namespace:, root: nil, separator: nil, timestamp_formatter: nil)
|
23
|
+
@timestamp_formatter = timestamp_formatter || DefaultConfig.instance.timestamp_formatter
|
24
|
+
@separator = separator || DefaultConfig.instance.separator
|
23
25
|
@namespace = []
|
24
26
|
@namespace = normalize_segments(namespace) if namespace.present?
|
25
|
-
@
|
26
|
-
@timestamp_formatter = timestamp_formatter || DefaultConfig.instance.timestamp_formatter
|
27
|
-
@root = root || namespace.last
|
27
|
+
@root = root || @namespace.last
|
28
28
|
end
|
29
29
|
|
30
30
|
# Create a new Keyspace, extending the namespace with the given segments and
|
@@ -70,7 +70,7 @@ module AtomicCache
|
|
70
70
|
def normalize_segments(segments)
|
71
71
|
if segments.is_a? Array
|
72
72
|
segments.map { |seg| expand_segment(seg) }
|
73
|
-
elsif
|
73
|
+
elsif segments.nil?
|
74
74
|
[]
|
75
75
|
else
|
76
76
|
[expand_segment(segments)]
|
data/lib/atomic_cache/version.rb
CHANGED
@@ -82,6 +82,13 @@ describe 'AtomicCacheConcern' do
|
|
82
82
|
expect(ns2_value).to eq('new-buz')
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
it 'works on the instance method' do
|
87
|
+
time = Time.local(2018, 1, 1, 15, 30, 0)
|
88
|
+
subject.new.expire_cache(time)
|
89
|
+
expect(key_storage.store).to have_key(:'foo1:lmt')
|
90
|
+
expect(key_storage.read(:'foo1:lmt')).to eq(time.to_i)
|
91
|
+
end
|
85
92
|
end
|
86
93
|
|
87
94
|
context '#cache_keyspace' do
|
@@ -6,29 +6,48 @@ describe 'Keyspace' do
|
|
6
6
|
subject { AtomicCache::Keyspace.new(namespace: ['foo', 'bar'], root: 'foo') }
|
7
7
|
|
8
8
|
context '#initialize' do
|
9
|
-
it 'hashes non-primitive types' do
|
10
|
-
ids = [1,2,3]
|
11
|
-
ns1 = AtomicCache::Keyspace.new(namespace: ['foo', ids])
|
12
|
-
hash = ns1.send(:hexhash, ids)
|
13
|
-
expect(ns1.namespace).to eq(['foo', hash])
|
14
|
-
end
|
15
9
|
|
16
|
-
it '
|
17
|
-
|
18
|
-
|
10
|
+
it 'sorts sortable values before hashing' do
|
11
|
+
ks1 = AtomicCache::Keyspace.new(namespace: ['foo', [1, 2, 3]])
|
12
|
+
ks2 = AtomicCache::Keyspace.new(namespace: ['foo', [3, 2, 1]])
|
13
|
+
expect(ks1.namespace).to eq(ks2.namespace)
|
19
14
|
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
context 'namespace' do
|
17
|
+
it 'accepts nil' do
|
18
|
+
ks = AtomicCache::Keyspace.new(namespace: nil)
|
19
|
+
expect(ks.namespace).to eq([])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'accepts single values' do
|
23
|
+
ks = AtomicCache::Keyspace.new(namespace: 'foo')
|
24
|
+
expect(ks.namespace).to eq(['foo'])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'hashes non-primitive types' do
|
28
|
+
ids = [1,2,3]
|
29
|
+
ks1 = AtomicCache::Keyspace.new(namespace: ['foo', ids])
|
30
|
+
hash = ks1.send(:hexhash, ids)
|
31
|
+
expect(ks1.namespace).to eq(['foo', hash])
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'leaves primitives alone' do
|
35
|
+
ks1 = AtomicCache::Keyspace.new(namespace: ['foo', :foo, 5])
|
36
|
+
expect(ks1.namespace).to eq(['foo', :foo, 5])
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'expands timestamps' do
|
40
|
+
formatter = Proc.new { |t| 'formatted' }
|
41
|
+
ks = AtomicCache::Keyspace.new(namespace: Time.new, timestamp_formatter: formatter)
|
42
|
+
expect(ks.namespace).to eq(['formatted'])
|
43
|
+
end
|
25
44
|
end
|
26
45
|
end
|
27
46
|
|
28
47
|
context '#child' do
|
29
48
|
it 'extends the keyspace' do
|
30
|
-
|
31
|
-
expect(
|
49
|
+
ks2 = subject.child([:buz, :baz])
|
50
|
+
expect(ks2.namespace).to eq(['foo', 'bar', :buz, :baz])
|
32
51
|
end
|
33
52
|
end
|
34
53
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atomic_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ibotta Developers
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|