You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-76Lines changed: 14 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,76 +4,15 @@ Solid Cache is a database-backed Active Support cache store that let's you keep
4
4
5
5
## Installation
6
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 using `bundle add solid_cache`.
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
8
9
-
#### Cache database configuration
9
+
1.`bundle add solid_cache`
10
+
2.`bin/rails solid_cache:install`
11
+
3.`bin/rails db:migrate`
10
12
11
-
The default installation of Solid Cache expects a database named `cache` in `database.yml`. It should
12
-
have it's own connection pool to avoid mixing cache queries in other transactions.
13
+
This will configure Solid Queue as the production cache store, create `config/solid_cache.yml`, and alter `config/database.yml` to include the new cache database.
13
14
14
-
You can use the primary database for your cache like this:
15
-
16
-
```yaml
17
-
# config/database.yml
18
-
production:
19
-
primary: &production_primary
20
-
...
21
-
cache:
22
-
<<: *production_primary
23
-
```
24
-
25
-
Or a separate database like this:
26
-
27
-
```yaml
28
-
production:
29
-
primary:
30
-
...
31
-
cache:
32
-
database: cache_development
33
-
host: 127.0.0.1
34
-
migrations_paths: "db/cache/migrate"
35
-
```
36
-
37
-
#### Install Solid Cache
38
-
39
-
Now, you need to install the necessary migrations and configure the cache store. You can do both at once using the provided generator:
And set Solid Cache as your application's cache store backend manually, in your environment config:
62
-
63
-
```ruby
64
-
# config/environments/production.rb
65
-
config.cache_store =:solid_cache_store
66
-
```
67
-
68
-
#### Run migrations
69
-
70
-
Finally, you need to run the migrations:
71
-
72
-
```bash
73
-
$ bin/rails db:migrate
74
-
```
75
-
76
-
### Configuration
15
+
## Configuration
77
16
78
17
Configuration will be read from `config/solid_cache.yml`. You can change the location of the config file by setting the `SOLID_CACHE_CONFIG` env variable.
79
18
@@ -101,7 +40,7 @@ production: &production
101
40
102
41
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.
103
42
104
-
#### Connection configuration
43
+
### Connection configuration
105
44
106
45
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`.
If `connects_to` is set, it will be passed directly.
121
60
122
-
If none of these are set, Solid Cache will use the `ActiveRecord::Base` connection pool. This means that cache reads and writes will be part of any wrapping
123
-
database transaction.
61
+
If none of these are set, Solid Cache will use the `ActiveRecord::Base` connection pool. This means that cache reads and writes will be part of any wrapping database transaction.
124
62
125
-
#### Engine configuration
63
+
### Engine configuration
126
64
127
65
There are three options that can be set on the engine:
128
66
@@ -140,7 +78,7 @@ Rails.application.configure do
140
78
end
141
79
```
142
80
143
-
#### Cache configuration
81
+
### Cache configuration
144
82
145
83
Solid Cache supports these options in addition to the standard `ActiveSupport::Cache::Store` options:
146
84
@@ -160,7 +98,7 @@ Solid Cache supports these options in addition to the standard `ActiveSupport::C
160
98
161
99
For more information on cache clusters, see [Sharding the cache](#sharding-the-cache)
162
100
163
-
### Cache expiry
101
+
## Cache expiry
164
102
165
103
Solid Cache tracks writes to the cache. For every write it increments a counter by 1. Once the counter reaches 50% of the `expiry_batch_size` it adds a task to run on a background thread. That task will:
166
104
@@ -176,7 +114,7 @@ Only triggering expiry when we write means that if the cache is idle, the backgr
176
114
177
115
If you want the cache expiry to be run in a background job instead of a thread, you can set `expiry_method` to `:job`. This will enqueue a `SolidCache::ExpiryJob`.
178
116
179
-
### Sharding the cache
117
+
## Sharding the cache
180
118
181
119
Solid Cache uses the [Maglev](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/44824.pdf) consistent hashing scheme to shard the cache across multiple databases.
0 commit comments