Suor / django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
BSD 3-Clause "New" or "Revised" License
2.1k stars 227 forks source link

Issue with transaction state list sync when for testing, one db(replica) mirrors another one. #417

Closed shikhart98 closed 2 years ago

shikhart98 commented 2 years ago

I have 2 DBs:

  1. Default
  2. Replica (ie. a read replica in production)

In my Django setting for the purpose of testing and running unit test cases, I have configured replica to mirror default DB. I was writing test case with the following scenario:

-> read request (using default DB): makes a query to DB to count the number of rows in a table. -> read request (using replica DB): makes a query to DB to count the number of rows in a table. -> insert request (using default DB) -> read request (using default DB): makes a query to db to count the number of rows in a table. -> read request (using replica DB): returns the count from cache (incorrect, should have queried DB).

Should cacheops not read the mirror property in case of TESTing, and maintain (sync) the list of transaction state it maintains for different database aliases?

Suor commented 2 years ago

By default cacheops presumes queries do not depend on database, which is desirable for a very common master-replica case. If you want those queries to be separate you need to set db_agnostic option to False, see https://github.com/Suor/django-cacheops#multiple-database-support