Skip to content

Commit c9a2089

Browse files
committed
Rework the connects_to configuration in the README
Prefer suggesting YAML configuration and show the how the `database` and `databases` shorthands map to `connects_to`.
1 parent f3d5aaa commit c9a2089

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,32 @@ config.cache_store = :solid_cache_store
8888

8989
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`.
9090

91-
Setting `database` to `cache_db` will configure with:
91+
If `connects_to` is set, it will be passed directly.
9292

93-
```ruby
94-
SolidCache::Record.connects_to database: { writing: :cache_db }
95-
```
93+
Setting `database` is shorthand for connecting to a single database:
9694

97-
Setting `databases` to `[cache_db, cache_db2]` is the equivalent of:
95+
```yaml
96+
database: :cache_db
9897
99-
```ruby
100-
SolidCache::Record.connects_to shards: { cache_db1: { writing: :cache_db1 }, cache_db2: { writing: :cache_db2 } }
98+
# equivalent to
99+
connects_to:
100+
database:
101+
writing: :cache_db
101102
```
102103

103-
If `connects_to` is set, it will be passed directly.
104+
And `databases` to `[cache_db, cache_db2]` configures multiple database shards:
105+
106+
```yaml
107+
databases: [cache_db, cache_db2]
108+
109+
# equivalent to
110+
connects_to:
111+
shards:
112+
cache_db1:
113+
writing: :cache_db1
114+
cache_db2:
115+
writing: :cache_db2
116+
```
104117

105118
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.
106119

0 commit comments

Comments
 (0)