README.md in distribute_reads-0.2.3 vs README.md in distribute_reads-0.2.4
- old
+ new
@@ -70,15 +70,29 @@
end
```
You can pass any options as well.
+## Lazy Evaluation
+
+ActiveRecord uses [lazy evaluation](https://www.theodinproject.com/courses/ruby-on-rails/lessons/active-record-queries), which can delay the execution of a query to outside of a `distribute_reads` block. In this case, the primary will be used.
+
+```ruby
+users = distribute_reads { User.where(orders_count: 1) } # not executed yet
+```
+
+Call `to_a` inside the block ensure the query runs on a replica.
+
+```ruby
+users = distribute_reads { User.where(orders_count: 1).to_a }
+```
+
## Options
### Replica Lag
-Raise an error when replica lag is too high
+Raise an error when replica lag is too high (specified in seconds)
```ruby
distribute_reads(max_lag: 3) do
# raises DistributeReads::TooMuchLag
end
@@ -129,26 +143,20 @@
```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
```
## Reference
-Get replication lag
+Get replication lag in seconds
```ruby
DistributeReads.replication_lag
```