solid_cache_mongoid 0.1.0 → 0.2.0
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 +117 -143
- data/app/models/solid_cache_mongoid/entry/size/estimate.rb +5 -4
- data/app/models/solid_cache_mongoid/entry/size/moving_average_estimate.rb +1 -1
- data/app/models/solid_cache_mongoid/entry.rb +2 -2
- data/app/models/solid_cache_mongoid/record.rb +3 -3
- data/lib/generators/{solid_cache → solid_cache_mongoid}/install/templates/config/cache.yml.tt +2 -2
- data/lib/solid_cache_mongoid/version.rb +1 -1
- metadata +5 -9
- data/lib/generators/solid_cache/install/templates/db/cache_schema.rb +0 -12
- data/lib/generators/solid_cache/install/templates/db/cache_structure.mysql.sql +0 -56
- data/lib/generators/solid_cache/install/templates/db/cache_structure.postgresql.sql +0 -128
- data/lib/generators/solid_cache/install/templates/db/cache_structure.sqlite3.sql +0 -6
- /data/lib/generators/{solid_cache → solid_cache_mongoid}/install/USAGE +0 -0
- /data/lib/generators/{solid_cache → solid_cache_mongoid}/install/install_generator.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0a03bc074cafd74ca8702ecf9adbe0ebff49846a848d4d11d2acb3ed304547e
|
|
4
|
+
data.tar.gz: f8394194bdddca35cf85f46bbcd556e5b10e4342f5c45930d695ff780dcbc942
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 947dd55858789b134d31497476cb2881153a14576c86fa2cf27d56aadbd867215d53a78faf66660f930a20648eaf2e961d28b4aafffe3179dbcc6bd611a86a28
|
|
7
|
+
data.tar.gz: 1241fc8dbe3dfca7f5e0206ad42b795ebe2a328cd9ecd5d31e615311c9aac343068f5434e5c95d68b7bb0fb4d5aee056a5ebc044e9e39e9869e9a3d156ea628a
|
data/README.md
CHANGED
|
@@ -1,189 +1,163 @@
|
|
|
1
|
-
# Solid Cache
|
|
1
|
+
# Solid Cache for Mongoid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://rubygems.org/gems/solid_cache_mongoid)
|
|
4
|
+
[](https://rubygems.org/gems/solid_cache_mongoid)
|
|
5
|
+
[](MIT-LICENSE)
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Solid Cache is configured by default in new Rails 8 applications. But if you're running an earlier version, you can add it manually following these steps:
|
|
8
|
-
|
|
9
|
-
1. `bundle add solid_cache_mongoid`
|
|
10
|
-
2. `bin/rails solid_cache_mongoid:install`
|
|
11
|
-
|
|
12
|
-
This will configure Solid Cache as the production cache store and create `config/cache.yml`.
|
|
13
|
-
|
|
14
|
-
## Configuration
|
|
7
|
+
A database-backed `ActiveSupport::Cache::Store` for Rails applications that run
|
|
8
|
+
on **MongoDB**.
|
|
15
9
|
|
|
16
|
-
|
|
10
|
+
Rails 8 ships [Solid Cache](https://github.com/rails/solid_cache), which trades
|
|
11
|
+
RAM for disk: modern SSDs are fast enough that a large cache on disk beats a
|
|
12
|
+
small cache in memory for most workloads. But Solid Cache is built on Active
|
|
13
|
+
Record. An application backed by Mongoid cannot use it, and gets pushed onto
|
|
14
|
+
Redis or Memcached for caching alone — one more service to run, pay for, and be
|
|
15
|
+
paged about.
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```yml
|
|
21
|
-
default: &default
|
|
22
|
-
# database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "solid_cache") %>
|
|
23
|
-
# collection: solid_cache_entries
|
|
24
|
-
# client: default
|
|
25
|
-
# encrypt: false
|
|
26
|
-
store_options:
|
|
27
|
-
# Cap age of oldest cache entry to fulfill retention policies
|
|
28
|
-
# max_age: <%%= 60.days.to_i %>
|
|
29
|
-
max_size: <%%= 256.megabytes %>
|
|
30
|
-
namespace: <%%= Rails.env %>
|
|
31
|
-
|
|
32
|
-
development:
|
|
33
|
-
<<: *default
|
|
17
|
+
This is Solid Cache rewritten on Mongoid, so those applications can cache
|
|
18
|
+
against the database they already have.
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
<<: *default
|
|
37
|
-
|
|
38
|
-
production:
|
|
39
|
-
database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "solid_cache") %>
|
|
40
|
-
<<: *default
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
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.
|
|
45
|
-
|
|
46
|
-
After running `solid_cache:install`, `environments/production.rb` will replace your cache store with Solid Cache, but you can also do this manually:
|
|
20
|
+
## Installation
|
|
47
21
|
|
|
48
22
|
```ruby
|
|
49
|
-
#
|
|
50
|
-
|
|
23
|
+
# Gemfile
|
|
24
|
+
gem "solid_cache_mongoid"
|
|
51
25
|
```
|
|
52
|
-
### Engine configuration
|
|
53
|
-
|
|
54
|
-
There are five options that can be set on the engine:
|
|
55
|
-
|
|
56
|
-
- `executor` - the [Rails executor](https://guides.rubyonrails.org/threading_and_code_execution.html#executor) used to wrap asynchronous operations, defaults to the app executor
|
|
57
|
-
- `size_estimate_samples` - if `max_size` is set on the cache, the number of the samples used to estimate the size.
|
|
58
|
-
- `encrypted` - whether cache values should be encrypted (see [Enabling encryption](#enabling-encryption))
|
|
59
|
-
- `encryption_context_properties` - custom encryption context properties
|
|
60
26
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Rails.application.configure do
|
|
65
|
-
config.solid_cache.size_estimate_samples = 1000
|
|
66
|
-
end
|
|
27
|
+
```sh
|
|
28
|
+
bundle install
|
|
29
|
+
bin/rails generate solid_cache_mongoid:install
|
|
67
30
|
```
|
|
68
31
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Solid Cache supports these options in addition to the standard `ActiveSupport::Cache::Store` options:
|
|
32
|
+
The generator writes `config/cache.yml` and points `config.cache_store` at
|
|
33
|
+
`:solid_cache_mongoid_store` in development, test and production.
|
|
72
34
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
- `expiry_queue` - which queue to add expiry jobs to (default: `default`)
|
|
77
|
-
- `max_age` - the maximum age of entries in the cache (default: `2.weeks.to_i`). Can be set to `nil`, but this is not recommended unless using `max_entries` to limit the size of the cache.
|
|
78
|
-
- `max_entries` - the maximum number of entries allowed in the cache (default: `nil`, meaning no limit)
|
|
79
|
-
- `max_size` - the maximum size of the cache entries (default `nil`, meaning no limit)
|
|
80
|
-
- `cluster` - (deprecated) a Hash of options for the cache database cluster, e.g `{ shards: [:database1, :database2, :database3] }`
|
|
81
|
-
- `clusters` - (deprecated) an Array of Hashes for multiple cache clusters (ignored if `:cluster` is set)
|
|
82
|
-
- `shards` - an Array of databases
|
|
83
|
-
- `active_record_instrumentation` - whether to instrument the cache's queries (default: `true`)
|
|
84
|
-
- `clear_with` - clear the cache with `:truncate` or `:delete` (default `truncate`, except for when `Rails.env.test?` then `delete`)
|
|
85
|
-
- `max_key_bytesize` - the maximum size of a normalized key in bytes (default `1024`)
|
|
35
|
+
There is no migration to run. The collection is created on first write and the
|
|
36
|
+
indexes are declared on the model — a unique index on `key_hash` for lookups,
|
|
37
|
+
plus `byte_size` and a compound `key_hash + byte_size` used by size estimation.
|
|
86
38
|
|
|
87
|
-
|
|
39
|
+
Requires Rails >= 7.2 (< 8.1) and Mongoid >= 9.
|
|
88
40
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
1. Check if we have exceeded the `max_entries` or `max_size` values (if set).
|
|
92
|
-
The current entries are estimated by subtracting the max and min IDs from the `SolidCache::Entry` table.
|
|
93
|
-
The current size is estimated by sampling the entry `byte_size` columns.
|
|
94
|
-
2. If we have, it will delete `expiry_batch_size` entries.
|
|
95
|
-
3. If not, it will delete up to `expiry_batch_size` entries, provided they are all older than `max_age`.
|
|
96
|
-
|
|
97
|
-
Expiring when we reach 50% of the batch size allows us to expire records from the cache faster than we write to it when we need to reduce the cache size.
|
|
41
|
+
## Configuration
|
|
98
42
|
|
|
99
|
-
|
|
43
|
+
The cache always lives in its own Mongo database — `solid_cache_mongoid` unless
|
|
44
|
+
you name another one — in a `solid_cache_entries` collection. It never shares
|
|
45
|
+
the application's database, so cache traffic and application traffic can be
|
|
46
|
+
pointed at different clients, and dropping the cache can never touch business
|
|
47
|
+
data.
|
|
100
48
|
|
|
101
|
-
|
|
49
|
+
`config/cache.yml`:
|
|
102
50
|
|
|
103
|
-
|
|
51
|
+
```yaml
|
|
52
|
+
default: &default
|
|
53
|
+
database: solid_cache_mongoid
|
|
54
|
+
store_options:
|
|
55
|
+
max_age: <%= 60.days.to_i %>
|
|
56
|
+
max_size: <%= 256.megabytes %>
|
|
57
|
+
namespace: <%= Rails.env %>
|
|
104
58
|
|
|
105
|
-
|
|
59
|
+
development:
|
|
60
|
+
<<: *default
|
|
106
61
|
|
|
107
|
-
```yaml
|
|
108
|
-
# config/cache.yml
|
|
109
62
|
production:
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
or
|
|
113
|
-
```ruby
|
|
114
|
-
# application.rb
|
|
115
|
-
config.solid_cache.encrypt = true
|
|
63
|
+
<<: *default
|
|
116
64
|
```
|
|
117
65
|
|
|
118
|
-
|
|
66
|
+
Top-level options:
|
|
119
67
|
|
|
120
|
-
|
|
121
|
-
|
|
68
|
+
| Option | Default | What it does |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `database` | `solid_cache_mongoid` | Mongo database holding the cache. |
|
|
71
|
+
| `collection` | `solid_cache_entries` | Collection name. |
|
|
72
|
+
| `client` | — | Mongoid client to use, if not the default one. |
|
|
73
|
+
| `encrypt` | `false` | Encrypt keys and values at rest. |
|
|
74
|
+
| `encryption_context_properties` | `{ deterministic: false }` | Passed to Mongoid encryption. |
|
|
75
|
+
| `size_estimate_samples` | `10_000` | Documents sampled when estimating cache size. |
|
|
122
76
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
deterministic: false
|
|
127
|
-
}
|
|
128
|
-
```
|
|
77
|
+
`store_options` are handed to the cache store itself: `max_age`, `max_size`,
|
|
78
|
+
`max_entries`, `namespace`, `expiry_batch_size`, `expiry_method`,
|
|
79
|
+
`expiry_queue`.
|
|
129
80
|
|
|
130
|
-
|
|
131
|
-
The Solid Cache migrations try to create an index with 1024 byte entries. If that is too big for your database, you should:
|
|
81
|
+
### Encryption at rest
|
|
132
82
|
|
|
133
|
-
|
|
134
|
-
|
|
83
|
+
Setting `encrypt: true` turns on Mongoid field encryption for `key` and
|
|
84
|
+
`value`, keyed from `SOLID_CACHE_KEY_ENCRYPT` or, absent that, the
|
|
85
|
+
application's `secret_key_base`. Encryption is non-deterministic by default:
|
|
86
|
+
the same value encrypts differently each time, so an attacker reading the
|
|
87
|
+
collection cannot tell which entries hold the same content.
|
|
135
88
|
|
|
136
|
-
##
|
|
89
|
+
## How expiry works
|
|
137
90
|
|
|
138
|
-
|
|
91
|
+
Expiry is not a cron job. Writes trigger it probabilistically, so the cache
|
|
92
|
+
trims itself in proportion to how hard it is being used and an idle
|
|
93
|
+
application does no work at all.
|
|
139
94
|
|
|
140
|
-
|
|
95
|
+
Each pass asks for three times as many candidates as it intends to delete and
|
|
96
|
+
then randomly samples down to the real count. That is deliberate: with several
|
|
97
|
+
workers expiring concurrently, taking the first N of an ordered list means
|
|
98
|
+
every worker fights over the same documents. Oversampling and choosing at
|
|
99
|
+
random keeps their working sets mostly disjoint.
|
|
141
100
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
101
|
+
Candidates are ordered by `_id`. A BSON `ObjectId` begins with a 4-byte
|
|
102
|
+
timestamp, so `_id` order is creation order — the same property upstream gets
|
|
103
|
+
from an autoincrementing primary key — which means age-based expiry needs no
|
|
104
|
+
index on `created_at`.
|
|
145
105
|
|
|
146
|
-
|
|
106
|
+
## What is different from upstream Solid Cache
|
|
147
107
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
```
|
|
108
|
+
The port is not a search-and-replace of `ApplicationRecord` for a Mongoid
|
|
109
|
+
model. The parts of Solid Cache that lean on SQL semantics had to be rebuilt.
|
|
151
110
|
|
|
111
|
+
**Locking.** Upstream uses Active Record transactions and database advisory
|
|
112
|
+
locks so concurrent expiry passes do not collide. MongoDB has no advisory
|
|
113
|
+
locks, so this uses [`mongoid-locker`](https://github.com/mongoid/mongoid-locker),
|
|
114
|
+
which takes a document-level lock through `locking_name` and `locked_at`
|
|
115
|
+
fields on the entry itself.
|
|
152
116
|
|
|
153
|
-
|
|
117
|
+
**Binary storage.** Keys and values are `BSON::Binary`, not SQL `BLOB`
|
|
118
|
+
columns, and are unwrapped on read. Serialized cache values are arbitrary
|
|
119
|
+
bytes; letting BSON infer a type would corrupt them.
|
|
154
120
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
121
|
+
**Key hashing.** Lookups match on a 64-bit hash of the key, clamped to
|
|
122
|
+
`-(2**63)..(2**63 - 1)` so it fits BSON's `int64`. The index stays small and
|
|
123
|
+
fixed-width regardless of how long the application's cache keys are. The hash
|
|
124
|
+
is also uniformly distributed, which is what makes the sampling below work.
|
|
158
125
|
|
|
159
|
-
|
|
126
|
+
**Row counting.** Upstream estimates how many rows the table holds by
|
|
127
|
+
subtracting the smallest primary key from the largest — cheap and accurate
|
|
128
|
+
with an autoincrementing integer. ObjectIds are not subtractable that way, so
|
|
129
|
+
this port counts documents instead.
|
|
160
130
|
|
|
161
|
-
|
|
162
|
-
|
|
131
|
+
**Query cache.** `without_query_cache` maps onto `Mongo::QueryCache.uncached`
|
|
132
|
+
rather than Active Record's connection-level query cache.
|
|
163
133
|
|
|
164
|
-
|
|
134
|
+
**Sharding.** Upstream can spread the cache across several databases through
|
|
135
|
+
`connects_to`. This port runs against a single unmanaged connection.
|
|
136
|
+
Applications that need to shard should shard in MongoDB.
|
|
165
137
|
|
|
166
|
-
|
|
167
|
-
bundle exec appraisal rails-7-1 bin/rake test
|
|
168
|
-
```
|
|
138
|
+
## Size estimation
|
|
169
139
|
|
|
170
|
-
|
|
140
|
+
Storing a `byte_size` per document makes the total cache size estimable
|
|
141
|
+
without scanning the collection:
|
|
171
142
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
143
|
+
1. Take the N largest documents by `byte_size` — there is an index for it — and
|
|
144
|
+
sum them exactly. These are the outliers that would otherwise skew any
|
|
145
|
+
sample.
|
|
146
|
+
2. Use the smallest of those as a cutoff, and sample the rest through a random
|
|
147
|
+
window of the `key_hash` range. Because `key_hash` is uniformly distributed
|
|
148
|
+
and indexed together with `byte_size`, the sum comes straight out of the
|
|
149
|
+
index.
|
|
150
|
+
3. Scale the sampled sum back up by the sampling fraction and add the outliers.
|
|
176
151
|
|
|
177
|
-
|
|
152
|
+
The result is an estimate whose cost does not grow with the size of the cache.
|
|
178
153
|
|
|
179
|
-
##
|
|
154
|
+
## Batching
|
|
180
155
|
|
|
181
|
-
|
|
156
|
+
`read_multi` and `write_multi` slice their input into batches of 1000, so a
|
|
157
|
+
wide `fetch_multi` costs a handful of round trips instead of one per key.
|
|
182
158
|
|
|
183
|
-
|
|
184
|
-
1. We don't need to track when items are read.
|
|
185
|
-
2. We can estimate and control the cache size by comparing the maximum and minimum IDs.
|
|
186
|
-
3. By deleting from one end of the table and adding at the other end we can avoid fragmentation.
|
|
159
|
+
## Credit
|
|
187
160
|
|
|
188
|
-
|
|
189
|
-
|
|
161
|
+
Original Solid Cache by [Donal McBreen](https://github.com/djmb) and 37signals.
|
|
162
|
+
Mongoid port by [Duvan Hernandez](https://github.com/duvanherfi). MIT licensed,
|
|
163
|
+
same as upstream.
|
|
@@ -21,8 +21,9 @@ module SolidCacheMongoid
|
|
|
21
21
|
# on key_hash and byte_size so we can grab a sum of the byte_sizes in a range of key_hash directly from that
|
|
22
22
|
# index.
|
|
23
23
|
#
|
|
24
|
-
# To decide how big the range should be, we
|
|
25
|
-
#
|
|
24
|
+
# To decide how big the range should be, we need the number of documents in the collection. Upstream Solid Cache
|
|
25
|
+
# subtracts the smallest primary key from the largest, which is cheap and accurate with an autoincrementing integer.
|
|
26
|
+
# ObjectIds cannot be subtracted that way, so here Entry.id_range counts the documents instead.
|
|
26
27
|
#
|
|
27
28
|
# We then calculate the fraction of the rows we want to sample by dividing the sample size by the estimated number
|
|
28
29
|
# of rows.
|
|
@@ -38,7 +39,7 @@ module SolidCacheMongoid
|
|
|
38
39
|
# outliers_cutoff OC = min(byte_size of N largest rows)
|
|
39
40
|
# outliers_size OS = sum(byte_size of N largest rows)
|
|
40
41
|
#
|
|
41
|
-
# estimated number of rows R =
|
|
42
|
+
# estimated number of rows R = number of documents in the collection
|
|
42
43
|
# sample_fraction F = N / R
|
|
43
44
|
# sample_range_size S = (Kmax - Kmin) * F
|
|
44
45
|
# sample range is K1..K2 where K1 = Kmin + rand(Kmax - S) and K2 = K1 + S
|
|
@@ -80,7 +81,7 @@ module SolidCacheMongoid
|
|
|
80
81
|
@outlier_size_and_cutoff ||= Entry.uncached do
|
|
81
82
|
largest = Entry.largest_byte_sizes(samples)
|
|
82
83
|
|
|
83
|
-
#
|
|
84
|
+
# Let MongoDB aggregate the sum, count and min
|
|
84
85
|
if largest.exists?
|
|
85
86
|
sum = largest.sum(:byte_size)
|
|
86
87
|
count = largest.count
|
|
@@ -32,7 +32,7 @@ module SolidCacheMongoid
|
|
|
32
32
|
value = Entry.read(ESTIMATES_KEY)
|
|
33
33
|
return [] unless value
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Unwrap BSON::Binary into a string when needed
|
|
36
36
|
value_str = value.is_a?(BSON::Binary) ? value.data : value.to_s
|
|
37
37
|
value_str.presence&.split("|")&.map(&:to_i) || []
|
|
38
38
|
end
|
|
@@ -28,7 +28,7 @@ module SolidCacheMongoid
|
|
|
28
28
|
without_query_cache do
|
|
29
29
|
payloads.each_slice(MULTI_BATCH_SIZE).each do |payload_batch|
|
|
30
30
|
add_key_hash_and_byte_size(payload_batch).each do |payload|
|
|
31
|
-
#
|
|
31
|
+
# Store key and value as BSON::Binary
|
|
32
32
|
key = payload.delete(:key)
|
|
33
33
|
value = payload.delete(:value)
|
|
34
34
|
obj = where(key_hash: payload[:key_hash]).first_or_initialize
|
|
@@ -54,7 +54,7 @@ module SolidCacheMongoid
|
|
|
54
54
|
where(:key_hash.in => key_hashes)
|
|
55
55
|
.only(:key, :value)
|
|
56
56
|
.each do |entry|
|
|
57
|
-
#
|
|
57
|
+
# Unwrap BSON::Binary back into a string
|
|
58
58
|
key_str = entry.key.data
|
|
59
59
|
value_str = entry.value.data
|
|
60
60
|
results[key_str] = value_str
|
|
@@ -42,7 +42,7 @@ module SolidCacheMongoid
|
|
|
42
42
|
ActiveSupport::Notifications.instrumenter = old
|
|
43
43
|
end
|
|
44
44
|
else
|
|
45
|
-
#
|
|
45
|
+
# Fall back to the previous behaviour, which used IsolatedExecutionState
|
|
46
46
|
old = ActiveSupport::IsolatedExecutionState[:active_record_instrumenter]
|
|
47
47
|
ActiveSupport::IsolatedExecutionState[:active_record_instrumenter] = instrumenter
|
|
48
48
|
begin
|
|
@@ -64,10 +64,10 @@ module SolidCacheMongoid
|
|
|
64
64
|
alias :cache :with_query_cache
|
|
65
65
|
|
|
66
66
|
def lease_connection
|
|
67
|
-
#
|
|
67
|
+
# The model's current Mongo client
|
|
68
68
|
client = self.mongo_client
|
|
69
69
|
|
|
70
|
-
#
|
|
70
|
+
# Make sure a connection is available
|
|
71
71
|
client.reconnect unless client.cluster.connected?
|
|
72
72
|
|
|
73
73
|
yield client
|
data/lib/generators/{solid_cache → solid_cache_mongoid}/install/templates/config/cache.yml.tt
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
default: &default
|
|
2
|
-
# database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "
|
|
2
|
+
# database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "solid_cache_mongoid") %>
|
|
3
3
|
# collection: solid_cache_entries
|
|
4
4
|
# client: default
|
|
5
5
|
# encrypt: false
|
|
@@ -16,5 +16,5 @@ test:
|
|
|
16
16
|
<<: *default
|
|
17
17
|
|
|
18
18
|
production:
|
|
19
|
-
database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "
|
|
19
|
+
database: <%= ENV.fetch("SOLID_CACHE_DATABASE", "solid_cache_mongoid") %>
|
|
20
20
|
<<: *default
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solid_cache_mongoid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Donal McBreen
|
|
8
8
|
- Duvan Hernandez
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mongoid
|
|
@@ -153,13 +153,9 @@ files:
|
|
|
153
153
|
- app/models/solid_cache_mongoid/entry/size/moving_average_estimate.rb
|
|
154
154
|
- app/models/solid_cache_mongoid/record.rb
|
|
155
155
|
- lib/active_support/cache/solid_cache_mongoid_store.rb
|
|
156
|
-
- lib/generators/
|
|
157
|
-
- lib/generators/
|
|
158
|
-
- lib/generators/
|
|
159
|
-
- lib/generators/solid_cache/install/templates/db/cache_schema.rb
|
|
160
|
-
- lib/generators/solid_cache/install/templates/db/cache_structure.mysql.sql
|
|
161
|
-
- lib/generators/solid_cache/install/templates/db/cache_structure.postgresql.sql
|
|
162
|
-
- lib/generators/solid_cache/install/templates/db/cache_structure.sqlite3.sql
|
|
156
|
+
- lib/generators/solid_cache_mongoid/install/USAGE
|
|
157
|
+
- lib/generators/solid_cache_mongoid/install/install_generator.rb
|
|
158
|
+
- lib/generators/solid_cache_mongoid/install/templates/config/cache.yml.tt
|
|
163
159
|
- lib/solid_cache_mongoid.rb
|
|
164
160
|
- lib/solid_cache_mongoid/configuration.rb
|
|
165
161
|
- lib/solid_cache_mongoid/connections.rb
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
ActiveRecord::Schema[7.2].define(version: 1) do
|
|
2
|
-
create_table "solid_cache_entries", force: :cascade do |t|
|
|
3
|
-
t.binary "key", limit: 1024, null: false
|
|
4
|
-
t.binary "value", limit: 536870912, null: false
|
|
5
|
-
t.datetime "created_at", null: false
|
|
6
|
-
t.integer "key_hash", limit: 8, null: false
|
|
7
|
-
t.integer "byte_size", limit: 4, null: false
|
|
8
|
-
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
|
|
9
|
-
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
|
|
10
|
-
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
3
|
-
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
4
|
-
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
5
|
-
/*!50503 SET NAMES utf8mb4 */;
|
|
6
|
-
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
|
7
|
-
/*!40103 SET TIME_ZONE='+00:00' */;
|
|
8
|
-
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
|
9
|
-
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
|
10
|
-
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
|
11
|
-
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
|
12
|
-
DROP TABLE IF EXISTS `ar_internal_metadata`;
|
|
13
|
-
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
14
|
-
/*!50503 SET character_set_client = utf8mb4 */;
|
|
15
|
-
CREATE TABLE `ar_internal_metadata` (
|
|
16
|
-
`key` varchar(255) NOT NULL,
|
|
17
|
-
`value` varchar(255) DEFAULT NULL,
|
|
18
|
-
`created_at` datetime(6) NOT NULL,
|
|
19
|
-
`updated_at` datetime(6) NOT NULL,
|
|
20
|
-
PRIMARY KEY (`key`)
|
|
21
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
22
|
-
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
23
|
-
DROP TABLE IF EXISTS `schema_migrations`;
|
|
24
|
-
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
25
|
-
/*!50503 SET character_set_client = utf8mb4 */;
|
|
26
|
-
CREATE TABLE `schema_migrations` (
|
|
27
|
-
`version` varchar(255) NOT NULL,
|
|
28
|
-
PRIMARY KEY (`version`)
|
|
29
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
30
|
-
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
31
|
-
DROP TABLE IF EXISTS `solid_cache_entries`;
|
|
32
|
-
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
33
|
-
/*!50503 SET character_set_client = utf8mb4 */;
|
|
34
|
-
CREATE TABLE `solid_cache_entries` (
|
|
35
|
-
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
36
|
-
`key` varbinary(1024) NOT NULL,
|
|
37
|
-
`value` longblob NOT NULL,
|
|
38
|
-
`created_at` datetime(6) NOT NULL,
|
|
39
|
-
`key_hash` bigint NOT NULL,
|
|
40
|
-
`byte_size` int NOT NULL,
|
|
41
|
-
PRIMARY KEY (`id`),
|
|
42
|
-
UNIQUE KEY `index_solid_cache_entries_on_key_hash` (`key_hash`),
|
|
43
|
-
KEY `index_solid_cache_entries_on_byte_size` (`byte_size`),
|
|
44
|
-
KEY `index_solid_cache_entries_on_key_hash_and_byte_size` (`key_hash`,`byte_size`)
|
|
45
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
46
|
-
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
47
|
-
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
|
48
|
-
|
|
49
|
-
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
|
50
|
-
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
|
51
|
-
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
|
52
|
-
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
|
53
|
-
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
|
54
|
-
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
|
55
|
-
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
|
56
|
-
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
SET statement_timeout = 0;
|
|
2
|
-
SET lock_timeout = 0;
|
|
3
|
-
SET idle_in_transaction_session_timeout = 0;
|
|
4
|
-
SET transaction_timeout = 0;
|
|
5
|
-
SET client_encoding = 'UTF8';
|
|
6
|
-
SET standard_conforming_strings = on;
|
|
7
|
-
SELECT pg_catalog.set_config('search_path', '', false);
|
|
8
|
-
SET check_function_bodies = false;
|
|
9
|
-
SET xmloption = content;
|
|
10
|
-
SET client_min_messages = warning;
|
|
11
|
-
SET row_security = off;
|
|
12
|
-
|
|
13
|
-
SET default_tablespace = '';
|
|
14
|
-
|
|
15
|
-
SET default_table_access_method = heap;
|
|
16
|
-
|
|
17
|
-
--
|
|
18
|
-
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
|
|
19
|
-
--
|
|
20
|
-
|
|
21
|
-
CREATE TABLE public.ar_internal_metadata (
|
|
22
|
-
key character varying NOT NULL,
|
|
23
|
-
value character varying,
|
|
24
|
-
created_at timestamp(6) without time zone NOT NULL,
|
|
25
|
-
updated_at timestamp(6) without time zone NOT NULL
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
--
|
|
30
|
-
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
|
|
31
|
-
--
|
|
32
|
-
|
|
33
|
-
CREATE TABLE public.schema_migrations (
|
|
34
|
-
version character varying NOT NULL
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
--
|
|
39
|
-
-- Name: solid_cache_entries; Type: TABLE; Schema: public; Owner: -
|
|
40
|
-
--
|
|
41
|
-
|
|
42
|
-
CREATE TABLE public.solid_cache_entries (
|
|
43
|
-
id bigint NOT NULL,
|
|
44
|
-
key bytea NOT NULL,
|
|
45
|
-
value bytea NOT NULL,
|
|
46
|
-
created_at timestamp(6) without time zone NOT NULL,
|
|
47
|
-
key_hash bigint NOT NULL,
|
|
48
|
-
byte_size integer NOT NULL
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
--
|
|
53
|
-
-- Name: solid_cache_entries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
|
54
|
-
--
|
|
55
|
-
|
|
56
|
-
CREATE SEQUENCE public.solid_cache_entries_id_seq
|
|
57
|
-
START WITH 1
|
|
58
|
-
INCREMENT BY 1
|
|
59
|
-
NO MINVALUE
|
|
60
|
-
NO MAXVALUE
|
|
61
|
-
CACHE 1;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
--
|
|
65
|
-
-- Name: solid_cache_entries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
|
66
|
-
--
|
|
67
|
-
|
|
68
|
-
ALTER SEQUENCE public.solid_cache_entries_id_seq OWNED BY public.solid_cache_entries.id;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
--
|
|
72
|
-
-- Name: solid_cache_entries id; Type: DEFAULT; Schema: public; Owner: -
|
|
73
|
-
--
|
|
74
|
-
|
|
75
|
-
ALTER TABLE ONLY public.solid_cache_entries ALTER COLUMN id SET DEFAULT nextval('public.solid_cache_entries_id_seq'::regclass);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
--
|
|
79
|
-
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
|
80
|
-
--
|
|
81
|
-
|
|
82
|
-
ALTER TABLE ONLY public.ar_internal_metadata
|
|
83
|
-
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
--
|
|
87
|
-
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
|
88
|
-
--
|
|
89
|
-
|
|
90
|
-
ALTER TABLE ONLY public.schema_migrations
|
|
91
|
-
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
--
|
|
95
|
-
-- Name: solid_cache_entries solid_cache_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
|
96
|
-
--
|
|
97
|
-
|
|
98
|
-
ALTER TABLE ONLY public.solid_cache_entries
|
|
99
|
-
ADD CONSTRAINT solid_cache_entries_pkey PRIMARY KEY (id);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
--
|
|
103
|
-
-- Name: index_solid_cache_entries_on_byte_size; Type: INDEX; Schema: public; Owner: -
|
|
104
|
-
--
|
|
105
|
-
|
|
106
|
-
CREATE INDEX index_solid_cache_entries_on_byte_size ON public.solid_cache_entries USING btree (byte_size);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
--
|
|
110
|
-
-- Name: index_solid_cache_entries_on_key_hash; Type: INDEX; Schema: public; Owner: -
|
|
111
|
-
--
|
|
112
|
-
|
|
113
|
-
CREATE UNIQUE INDEX index_solid_cache_entries_on_key_hash ON public.solid_cache_entries USING btree (key_hash);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
--
|
|
117
|
-
-- Name: index_solid_cache_entries_on_key_hash_and_byte_size; Type: INDEX; Schema: public; Owner: -
|
|
118
|
-
--
|
|
119
|
-
|
|
120
|
-
CREATE INDEX index_solid_cache_entries_on_key_hash_and_byte_size ON public.solid_cache_entries USING btree (key_hash, byte_size);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
--
|
|
124
|
-
-- PostgreSQL database dump complete
|
|
125
|
-
--
|
|
126
|
-
|
|
127
|
-
SET search_path TO "$user", public;
|
|
128
|
-
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
|
|
2
|
-
CREATE TABLE IF NOT EXISTS "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
|
|
3
|
-
CREATE TABLE IF NOT EXISTS "solid_cache_entries" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "key" blob(1024) NOT NULL, "value" blob(536870912) NOT NULL, "created_at" datetime(6) NOT NULL, "key_hash" integer(8) NOT NULL, "byte_size" integer(4) NOT NULL);
|
|
4
|
-
CREATE INDEX "index_solid_cache_entries_on_byte_size" ON "solid_cache_entries" ("byte_size");
|
|
5
|
-
CREATE INDEX "index_solid_cache_entries_on_key_hash_and_byte_size" ON "solid_cache_entries" ("key_hash", "byte_size");
|
|
6
|
-
CREATE UNIQUE INDEX "index_solid_cache_entries_on_key_hash" ON "solid_cache_entries" ("key_hash");
|
|
File without changes
|
|
File without changes
|