README.md in distribute_reads-0.1.2 vs README.md in distribute_reads-0.2.0
- old
+ new
@@ -68,24 +68,87 @@
# ...
end
end
```
+You can pass any options as well.
+
## Options
+### Replica Lag
+
Raise an error when replica lag is too high - *PostgreSQL only*
```ruby
distribute_reads(max_lag: 3) do
# raises DistributeReads::TooMuchLag
end
```
-Don’t default to primary (default Makara behavior)
+Instead of raising an error, you can also use primary
```ruby
-DistributeReads.default_to_primary = false
+distribute_reads(max_lag: 3, lag_failover: true) do
+ # ...
+end
```
+
+If you have multiple databases, this only checks lag on `ActiveRecord::Base` connection. Specify connections to check with
+
+```ruby
+distribute_reads(max_lag: 3, lag_on: [ApplicationRecord, LogRecord]) do
+ # ...
+end
+```
+
+**Note:** If lag on any connection exceeds the max lag and lag failover is used, *all connections* will use their primary.
+
+### Availability
+
+If no replicas are available, primary is used. To prevent this situation from overloading the primary, you can raise an error instead.
+
+```ruby
+distribute_reads(failover: false) do
+ # raises DistributeReads::NoReplicasAvailable
+end
+```
+
+### Default Options
+
+Change the defaults
+
+```ruby
+DistributeReads.default_options = {
+ lag_failover: true,
+ failover: false
+}
+```
+
+## Distribute Reads by Default
+
+At some point, you may wish to distribute reads by default.
+
+```ruby
+DistributeReads.by_default = true
+```
+
+Once you do this, Makara will use the Rails cache to track its state. To reduce load on the Rails cache, use a write-through cache in front of it.
+
+```ruby
+Makara::Cache.store = DistributeReads::CacheStore.new
+```
+
+To make queries go to primary, use:
+
+```ruby
+distribute_reads(primary: true) do
+ # ...
+end
+```
+
+## Thanks
+
+Thanks to [TaskRabbit](https://github.com/taskrabbit) for Makara and [Nick Elser](https://github.com/nickelser) for the write-through cache.
## History
View the [changelog](https://github.com/ankane/distribute_reads/blob/master/CHANGELOG.md)