atomic_cache 0.5.3.rc1 → 0.5.4.rc1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e912c124c9879b3208c849a21f6f82a665ddc0f3ab1e268a1355d6cfb7bda54a
|
4
|
+
data.tar.gz: 3fc8b8814852f95414e8c699fb2b6f17d4c0a0516f7bc12dbdb2d167096604ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5104f60b2f4f9d2816a53e7a19dcf58eda5e245b052c1d048c586cae8df985e0eb17f58c13bdc8dc07db4bb50607d033cb57c7a701db50a896955575cc710e3b
|
7
|
+
data.tar.gz: bae2d03aac48378a6075d648c9131cf265271192658e30b5191a6bb82735e7a4aae0162d62b0c4153ed46ad16d9375cf8c832bd899b408e3ab7a9617710d2f71
|
data/docs/MODEL_SETUP.md
CHANGED
@@ -29,3 +29,65 @@ class Foo < ActiveRecord::Base
|
|
29
29
|
cache_version(5)
|
30
30
|
end
|
31
31
|
```
|
32
|
+
|
33
|
+
### Inheritance
|
34
|
+
|
35
|
+
When either `force_cache_class` or `cache_version` are used, those values will always be preferred by classes which inherit from the class on which those macros exist. When macros are used on descendant classes, the "closet" value wins.
|
36
|
+
|
37
|
+
#### Example #1
|
38
|
+
The keys used by `Bar` will be prefixed with `custom:v5`, as it prefers both the 'custom' class name and version 5 from the parent.
|
39
|
+
```ruby
|
40
|
+
class Foo < ActiveRecord::Base
|
41
|
+
include AtomicCache::GlobalLMTCacheConcern
|
42
|
+
force_cache_class('custom')
|
43
|
+
cache_version(5)
|
44
|
+
end
|
45
|
+
|
46
|
+
class Bar < Foo
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Example #2
|
51
|
+
The keys used by `Bar` will be prefixed with `bar:v5`, as the version 5 is taken from the parent, but the use of forcing on the child class result in the cache class of 'bar'.
|
52
|
+
```ruby
|
53
|
+
class Foo < ActiveRecord::Base
|
54
|
+
include AtomicCache::GlobalLMTCacheConcern
|
55
|
+
cache_version(5)
|
56
|
+
end
|
57
|
+
|
58
|
+
class Bar < Foo
|
59
|
+
force_cache_class('bar')
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Example #3
|
64
|
+
The keys used by `Bar` will be still be prefixed with `bar:v5` for the same reasons as above.
|
65
|
+
```ruby
|
66
|
+
class Foo < ActiveRecord::Base
|
67
|
+
include AtomicCache::GlobalLMTCacheConcern
|
68
|
+
force_cache_class('custom')
|
69
|
+
cache_version(5)
|
70
|
+
end
|
71
|
+
|
72
|
+
class Bar < Foo
|
73
|
+
force_cache_class('bar')
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### Rails Model Inheritance
|
78
|
+
|
79
|
+
It's not uncommon in rails to end up with model inhertiance. For example:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class Content < ActiveRecord::Base
|
83
|
+
include AtomicCache::GlobalLMTCacheConcern
|
84
|
+
force_cache_class('content')
|
85
|
+
end
|
86
|
+
|
87
|
+
class BlogPost < Content
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
If these models will be cached together into a single key, it's preferable to force the cache class on the parent, causing all the descendant types to use the same keyspace. Not doing this will cause each subtype to use it's own last modified time.
|
92
|
+
|
93
|
+
If the models will be treated as separate collections and cached separately, this is not recommended. Alternately, if only some subtypes will be cached together, those should share a forced cache class and version.
|
@@ -63,15 +63,29 @@ module AtomicCache
|
|
63
63
|
@timestamp_manager.last_modified_time
|
64
64
|
end
|
65
65
|
|
66
|
+
# protected
|
67
|
+
|
68
|
+
def cache_version_get
|
69
|
+
return @atomic_cache_version if @atomic_cache_version.present?
|
70
|
+
return self.superclass.cache_version_get if self.superclass.respond_to?(:cache_version_get)
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def cache_class_get
|
75
|
+
return @atomic_cache_class if @atomic_cache_class.present?
|
76
|
+
return self.superclass.cache_class_get if self.superclass.respond_to?(:cache_class_get)
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
66
80
|
private
|
67
81
|
|
68
82
|
def init_atomic_cache
|
69
83
|
return if @atomic_cache.present?
|
70
84
|
ATOMIC_CACHE_CONCERN_MUTEX.synchronize do
|
71
|
-
cache_class =
|
85
|
+
cache_class = cache_class_get || default_cache_class
|
72
86
|
prefix = [cache_class]
|
73
87
|
prefix.unshift(DefaultConfig.instance.namespace) if DefaultConfig.instance.namespace.present?
|
74
|
-
prefix.push("v#{
|
88
|
+
prefix.push("v#{cache_version_get}") if cache_version_get.present?
|
75
89
|
@default_cache_keyspace = Keyspace.new(namespace: prefix, root: cache_class)
|
76
90
|
|
77
91
|
@timestamp_manager = LastModTimeKeyManager.new(
|
data/lib/atomic_cache/version.rb
CHANGED
@@ -113,6 +113,61 @@ describe 'AtomicCacheConcern' do
|
|
113
113
|
subject.expire_cache
|
114
114
|
expect(key_storage.store).to have_key(:'foo:v3:lmt')
|
115
115
|
end
|
116
|
+
|
117
|
+
context 'with version < class inheritance' do
|
118
|
+
subject do
|
119
|
+
class Foo3
|
120
|
+
include AtomicCache::GlobalLMTCacheConcern
|
121
|
+
cache_version(6)
|
122
|
+
end
|
123
|
+
class Foo4 < Foo3
|
124
|
+
force_cache_class('foo')
|
125
|
+
end
|
126
|
+
Foo4
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'uses the version from the parent and the forced class name from the macro' do
|
130
|
+
subject.expire_cache
|
131
|
+
expect(key_storage.store).to have_key(:'foo:v6:lmt')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'with class < version inheritance' do
|
136
|
+
subject do
|
137
|
+
class Foo5
|
138
|
+
include AtomicCache::GlobalLMTCacheConcern
|
139
|
+
force_cache_class('foo')
|
140
|
+
end
|
141
|
+
class Foo6 < Foo5
|
142
|
+
cache_version(6)
|
143
|
+
end
|
144
|
+
Foo6
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'uses the cache class from the parent and version from the macro' do
|
148
|
+
subject.expire_cache
|
149
|
+
expect(key_storage.store).to have_key(:'foo:v6:lmt')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'dual force_cache_class' do
|
154
|
+
subject do
|
155
|
+
class Foo6
|
156
|
+
include AtomicCache::GlobalLMTCacheConcern
|
157
|
+
force_cache_class('foo')
|
158
|
+
end
|
159
|
+
class Foo7 < Foo6
|
160
|
+
force_cache_class('bar')
|
161
|
+
cache_version(6)
|
162
|
+
end
|
163
|
+
Foo7
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'uses the prefers the forced class name from the macro' do
|
167
|
+
subject.expire_cache
|
168
|
+
expect(key_storage.store).to have_key(:'bar:v6:lmt')
|
169
|
+
end
|
170
|
+
end
|
116
171
|
end
|
117
172
|
|
118
173
|
context 'storage macros' do
|
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.5.
|
4
|
+
version: 0.5.4.rc1
|
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: 2021-08-
|
12
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -137,6 +137,20 @@ dependencies:
|
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: 0.8.1
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: pry
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
140
154
|
- !ruby/object:Gem::Dependency
|
141
155
|
name: activesupport
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|