atomic_cache 0.2.5.rc1 → 0.3.0.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: becad2b31944cbd2f93353a4b5e015f8f39c6f508f605f3adcd672fd7e8482b9
|
4
|
+
data.tar.gz: a76b093ad299c779adabe12053731f6582eca33b169a4b05c3a2c619f8747855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ea9a439a06adde2a837132820555a564aa2168344a9b9b455fcf04e3293aa3ce147ca9a534ed97266dda92a1db09aa0cc33af22262c6997f8dca334ac0ec66
|
7
|
+
data.tar.gz: 3e4c87333014f120f9ef8055492886734525cbc85ef5245fe87c32a3e908ce0ab059f5ea297a6bc3c2c05517c294ac6ee7891e0caa3d3d4f44db83ea3583fc64
|
data/README.md
CHANGED
data/docs/MODEL_SETUP.md
CHANGED
@@ -7,13 +7,13 @@ class Foo < ActiveRecord::Base
|
|
7
7
|
end
|
8
8
|
```
|
9
9
|
|
10
|
-
###
|
10
|
+
### force_cache_class
|
11
11
|
By default the cache identifier for a class is set to the name of a class (ie. `self.to_s`). In some cases it makes sense to set a custom value for the cache identifier. In cases where a custom cache identifier is set, it's important that the identifier remain unique across the project.
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
class SuperDescriptiveDomainModelAbstractFactoryImplManager < ActiveRecord::Base
|
15
15
|
include AtomicCache::GlobalLMTCacheConcern
|
16
|
-
|
16
|
+
force_cache_class('sddmafim')
|
17
17
|
end
|
18
18
|
```
|
19
19
|
|
data/docs/PROJECT_SETUP.md
CHANGED
@@ -23,9 +23,10 @@ AtomicCache::DefaultConfig.configure do |config|
|
|
23
23
|
config.metrics = Datadog::Statsd.new('localhost', 8125, namespace: 'cache.atomic')
|
24
24
|
|
25
25
|
# note: these values can also be set in an env file for env-specific settings
|
26
|
-
config.namespace
|
27
|
-
config.
|
28
|
-
config.
|
26
|
+
config.namespace = 'atom'
|
27
|
+
config.default_options = { generate_ttl_ms: 500 }
|
28
|
+
config.cache_storage = AtomicCache::Storage::SharedMemory.new
|
29
|
+
config.key_storage = AtomicCache::Storage::SharedMemory.new
|
29
30
|
end
|
30
31
|
```
|
31
32
|
|
@@ -36,7 +37,7 @@ Note that `Datadog::Statsd` is not _required_. Adding it, however, will enable
|
|
36
37
|
* `key_storage` - Storage adapter for key manager (see below)
|
37
38
|
|
38
39
|
#### Optional
|
39
|
-
* `default_options` -
|
40
|
+
* `default_options` - Override default options for every fetch call, unless specified at call site. See [fetch options](/Ibotta/atomic_cache/blob/main/docs/USAGE.md#fetch).
|
40
41
|
* `logger` - Logger instance. Used for debug and warn logs. Defaults to nil.
|
41
42
|
* `timestamp_formatter` - Proc to format last modified time for storage. Defaults to timestamp (`Time.to_i`)
|
42
43
|
* `metrics` - Metrics instance. Defaults to nil.
|
@@ -45,6 +46,49 @@ Note that `Datadog::Statsd` is not _required_. Adding it, however, will enable
|
|
45
46
|
#### ★ Best Practice ★
|
46
47
|
Keep the global namespace short. For example, memcached has a limit of 250 characters for key length.
|
47
48
|
|
49
|
+
#### More Complex Rails Configuration
|
50
|
+
|
51
|
+
In any real-world project, the need to run multiple caching strategies or setups is likely to arise. In those cases, it's often advantageous
|
52
|
+
to keep a DRY setup, with multiple caching clients sharing the same config. Because Rails initializers run after the environment-specific
|
53
|
+
config files, a sane way to manage this is to keep client network settings int he config files, then reference them from the initializer.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# config/environments/staging
|
57
|
+
config.memcache_hosts = [ "staging.host.cache.amazonaws.com" ]
|
58
|
+
config.cache_store_options = {
|
59
|
+
expires_in: 15.minutes,
|
60
|
+
compress: true,
|
61
|
+
# ...
|
62
|
+
}
|
63
|
+
|
64
|
+
# config/environments/production
|
65
|
+
config.memcache_hosts = [ "prod1.host.cache.amazonaws.com", "prod2.host.cache.amazonaws.com" ]
|
66
|
+
config.cache_store_options = {
|
67
|
+
expires_in: 1.hour,
|
68
|
+
compress: true,
|
69
|
+
# ...
|
70
|
+
}
|
71
|
+
|
72
|
+
# config/initializers/cache.rb
|
73
|
+
AtomicCache::DefaultConfig.configure do |config|
|
74
|
+
if Rails.env.development? || Rails.env.test?
|
75
|
+
config.cache_storage = AtomicCache::Storage::SharedMemory.new
|
76
|
+
config.key_storage = AtomicCache::Storage::SharedMemory.new
|
77
|
+
|
78
|
+
elsif Rails.env.staging? || Rails.env.production?
|
79
|
+
# Your::Application.config will be loaded by config/environments/*
|
80
|
+
memcache_hosts = Your::Application.config.memcache_hosts
|
81
|
+
options = Your::Application.config.cache_store_options
|
82
|
+
|
83
|
+
dc = Dalli::Client.new(memcache_hosts, options)
|
84
|
+
config.cache_storage = AtomicCache::Storage::Dalli.new(dc)
|
85
|
+
config.key_storage = AtomicCache::Storage::Dalli.new(dc)
|
86
|
+
end
|
87
|
+
|
88
|
+
# other AtomicCache configuration...
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
48
92
|
## Storage Adapters
|
49
93
|
|
50
94
|
### InstanceMemory & SharedMemory
|
data/lib/atomic_cache/version.rb
CHANGED
@@ -104,12 +104,12 @@ describe 'AtomicCacheConcern' do
|
|
104
104
|
class Foo2
|
105
105
|
include AtomicCache::GlobalLMTCacheConcern
|
106
106
|
cache_version(3)
|
107
|
-
|
107
|
+
force_cache_class('foo')
|
108
108
|
end
|
109
109
|
Foo2
|
110
110
|
end
|
111
111
|
|
112
|
-
it 'uses the given version and
|
112
|
+
it 'uses the given version and force_cache_class become part of the cache keyspace' do
|
113
113
|
subject.expire_cache
|
114
114
|
expect(key_storage.store).to have_key(:'foo:v3:lmt')
|
115
115
|
end
|
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.
|
4
|
+
version: 0.3.0.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-
|
12
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|