solid_cache 1.0.6 → 1.0.7
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/README.md +11 -4
- data/app/models/solid_cache/entry.rb +13 -5
- data/app/models/solid_cache/record.rb +14 -1
- data/lib/solid_cache/store/connections.rb +24 -25
- data/lib/solid_cache/store/expiry.rb +0 -2
- data/lib/solid_cache/store/failsafe.rb +0 -1
- data/lib/solid_cache/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c96752c871ba3eb453aca3f4c838b76afa0393486787109ef6e2f1ce1266a3d
|
4
|
+
data.tar.gz: 57cf865289e1c289ceed0b0103f234b61f5283c4a693ba213d60e4e81d21f9f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be0dad91c5e93e775c0f7f528106b0d8ca69709d3d6d1fe4d95e834249abd267b86c5828d857e173fa1357da967362d290079df47f27bbcbcf56c3b7e9c80683
|
7
|
+
data.tar.gz: ebc91d895a6721f1a8acf2ea4ee611bc8619aa3a432be492f9a934c7eae5796c6539cba51ebba9396245b5a09ca197cfbe6c8abd9c10fda60957c0f477987d51
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Solid Cache
|
2
2
|
|
3
|
-
Solid Cache is a database-backed Active Support cache store that
|
3
|
+
Solid Cache is a database-backed Active Support cache store that lets you keep a much larger cache than is typically possible with traditional memory-only Redis or Memcached stores. This is thanks to the speed of modern SSD drives, which make the access-time penalty of using disk vs RAM insignificant for most caching purposes. Simply put, you're now usually better off keeping a huge cache on disk rather than a small cache in memory.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -11,7 +11,7 @@ Solid Cache is configured by default in new Rails 8 applications. But if you're
|
|
11
11
|
|
12
12
|
This will configure Solid Cache as the production cache store, create `config/cache.yml`, and create `db/cache_schema.rb`.
|
13
13
|
|
14
|
-
You will then have to add the configuration for the
|
14
|
+
You will then have to add the configuration for the cache database in `config/database.yml`. If you're using sqlite, it'll look like this:
|
15
15
|
|
16
16
|
```yaml
|
17
17
|
production:
|
@@ -69,6 +69,13 @@ production: &production
|
|
69
69
|
|
70
70
|
For the full list of keys for `store_options` see [Cache configuration](#cache-configuration). Any options passed to the cache lookup will overwrite those specified here.
|
71
71
|
|
72
|
+
After running `solid_cache:install`, `environments/production.rb` will replace your cache store with Solid Cache, but you can also do this manually:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# config/environments/production.rb
|
76
|
+
config.cache_store = :solid_cache_store
|
77
|
+
```
|
78
|
+
|
72
79
|
### Connection configuration
|
73
80
|
|
74
81
|
You can set one of `database`, `databases` and `connects_to` in the config file. They will be used to configure the cache databases in `SolidCache::Record#connects_to`.
|
@@ -189,7 +196,7 @@ or
|
|
189
196
|
config.solid_cache.encrypt = true
|
190
197
|
```
|
191
198
|
|
192
|
-
You will need to set up your application to
|
199
|
+
You will need to set up your application to [use Active Record Encryption](https://guides.rubyonrails.org/active_record_encryption.html).
|
193
200
|
|
194
201
|
Solid Cache by default uses a custom encryptor and message serializer that are optimised for it.
|
195
202
|
|
@@ -260,7 +267,7 @@ This ensures that all the Rails versions dependencies are updated.
|
|
260
267
|
|
261
268
|
## Implementation
|
262
269
|
|
263
|
-
Solid Cache is a FIFO (first in, first out) cache. While this is not as efficient as an LRU cache, it is mitigated by the longer cache lifespan.
|
270
|
+
Solid Cache is a FIFO (first in, first out) cache. While this is not as efficient as an LRU (least recently used) cache, it is mitigated by the longer cache lifespan.
|
264
271
|
|
265
272
|
A FIFO cache is much easier to manage:
|
266
273
|
1. We don't need to track when items are read.
|
@@ -14,6 +14,8 @@ module SolidCache
|
|
14
14
|
|
15
15
|
KEY_HASH_ID_RANGE = -(2**63)..(2**63 - 1)
|
16
16
|
|
17
|
+
MULTI_BATCH_SIZE = 1000
|
18
|
+
|
17
19
|
class << self
|
18
20
|
def write(key, value)
|
19
21
|
write_multi([ { key: key, value: value } ])
|
@@ -21,9 +23,11 @@ module SolidCache
|
|
21
23
|
|
22
24
|
def write_multi(payloads)
|
23
25
|
without_query_cache do
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
payloads.each_slice(MULTI_BATCH_SIZE).each do |payload_batch|
|
27
|
+
upsert_all \
|
28
|
+
add_key_hash_and_byte_size(payload_batch),
|
29
|
+
unique_by: upsert_unique_by, on_duplicate: :update, update_only: [ :key, :value, :byte_size ]
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
@@ -33,9 +37,13 @@ module SolidCache
|
|
33
37
|
|
34
38
|
def read_multi(keys)
|
35
39
|
without_query_cache do
|
36
|
-
|
40
|
+
{}.tap do |results|
|
41
|
+
keys.each_slice(MULTI_BATCH_SIZE).each do |keys_batch|
|
42
|
+
query = Arel.sql(select_sql(keys_batch), *key_hashes_for(keys_batch))
|
37
43
|
|
38
|
-
|
44
|
+
results.merge!(connection.select_all(query, "SolidCache::Entry Load").cast_values(attribute_types).to_h)
|
45
|
+
end
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
@@ -10,7 +10,20 @@ module SolidCache
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def disable_instrumentation(&block)
|
13
|
-
|
13
|
+
with_instrumenter(NULL_INSTRUMENTER, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_instrumenter(instrumenter, &block)
|
17
|
+
if connection.respond_to?(:with_instrumenter)
|
18
|
+
connection.with_instrumenter(instrumenter, &block)
|
19
|
+
else
|
20
|
+
begin
|
21
|
+
old_instrumenter, ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = ActiveSupport::IsolatedExecutionState[:active_record_instrumenter], instrumenter
|
22
|
+
block.call
|
23
|
+
ensure
|
24
|
+
ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = old_instrumenter
|
25
|
+
end
|
26
|
+
end
|
14
27
|
end
|
15
28
|
|
16
29
|
def with_shard(shard, &block)
|
@@ -34,26 +34,6 @@ module SolidCache
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def with_connection_for(key, async: false, &block)
|
38
|
-
connections.with_connection_for(key) do
|
39
|
-
execute(async, &block)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def with_connection(name, async: false, &block)
|
44
|
-
connections.with(name) do
|
45
|
-
execute(async, &block)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def group_by_connection(keys)
|
50
|
-
connections.assign(keys)
|
51
|
-
end
|
52
|
-
|
53
|
-
def connection_names
|
54
|
-
connections.names
|
55
|
-
end
|
56
|
-
|
57
37
|
def connections
|
58
38
|
@connections ||= SolidCache::Connections.from_config(@shard_options)
|
59
39
|
end
|
@@ -63,6 +43,26 @@ module SolidCache
|
|
63
43
|
connections
|
64
44
|
end
|
65
45
|
|
46
|
+
def with_connection_for(key, async: false, &block)
|
47
|
+
connections.with_connection_for(key) do
|
48
|
+
execute(async, &block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_connection(name, async: false, &block)
|
53
|
+
connections.with(name) do
|
54
|
+
execute(async, &block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def group_by_connection(keys)
|
59
|
+
connections.assign(keys)
|
60
|
+
end
|
61
|
+
|
62
|
+
def connection_names
|
63
|
+
connections.names
|
64
|
+
end
|
65
|
+
|
66
66
|
def reading_key(key, failsafe:, failsafe_returning: nil, &block)
|
67
67
|
failsafe(failsafe, returning: failsafe_returning) do
|
68
68
|
with_connection_for(key, &block)
|
@@ -70,16 +70,15 @@ module SolidCache
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def reading_keys(keys, failsafe:, failsafe_returning: nil)
|
73
|
-
group_by_connection(keys).map do |connection,
|
73
|
+
group_by_connection(keys).map do |connection, grouped_keys|
|
74
74
|
failsafe(failsafe, returning: failsafe_returning) do
|
75
75
|
with_connection(connection) do
|
76
|
-
yield
|
76
|
+
yield grouped_keys
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
82
|
def writing_key(key, failsafe:, failsafe_returning: nil, &block)
|
84
83
|
failsafe(failsafe, returning: failsafe_returning) do
|
85
84
|
with_connection_for(key, &block)
|
@@ -87,10 +86,10 @@ module SolidCache
|
|
87
86
|
end
|
88
87
|
|
89
88
|
def writing_keys(entries, failsafe:, failsafe_returning: nil)
|
90
|
-
group_by_connection(entries).map do |connection,
|
89
|
+
group_by_connection(entries).map do |connection, grouped_entries|
|
91
90
|
failsafe(failsafe, returning: failsafe_returning) do
|
92
91
|
with_connection(connection) do
|
93
|
-
yield
|
92
|
+
yield grouped_entries
|
94
93
|
end
|
95
94
|
end
|
96
95
|
end
|
data/lib/solid_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Donal McBreen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.5.
|
161
|
+
rubygems_version: 3.5.22
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: A database backed ActiveSupport::Cache::Store
|