The database cache store can read from a read replica and miss fresh writes

Open
#847 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@yuriizee is already working on this.

Since Dec 4, 2026.

  • #870 by @yuriizee — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
backend, databases

Research direction

Start in src/cache/database.rs and read DatabaseStore::get alongside the write and increment paths to see how connection selection works. The issue suggests reading through the write connection or adding an option and documenting it in the cache guide. Done means database cache reads see fresh writes across requests; an open pull request is already linked.

Written by the indexing model from the issue text.

Description

DatabaseStore::get builds its query without use_write_connection(). On a connection with read replicas, a cache read can go to a lagging replica and return None (or an old value) for a key that another request or process has just written. Sticky reads only cover writes made in the same request.

That matters for cache uses that rely on read-after-write across processes: one-time tokens, counters read back after increment, a value written by one request and read by the next. Redis and memory stores don't have this gap, so the same code behaves differently on the database store.

// laravel-rust 0.2.0, src/cache/database.rs
async fn get(&self, key: &str) -> Result<Option<String>> {
    let values = self.values()?.filter(col("key").eq(key));
    let row = values
        .clone()
        .select(["value", "expiration"])
        .into_query()
        // no .use_write_connection()
        ...

Suggestion

Either read the cache table from the write connection (cache tables are small, and correctness beats offloading), or add a store option such as DatabaseStore::new().read_from_writer(true), and document the behaviour in the cache guide.

Seen on 0.2.0; the same code is on 0.x at 6156f0e.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.