Debug peewee cache hits

25 Views Asked by At

The docs say:

By default peewee will cache the rows returned when iterating over a Select query.

I would like to debug when peewee hits or misses this cache.

Looking at the source code, there's row_cache used in different places. Where should I insert a logger call?

I've already activated the peewee query logging. If a query is logged there, does it mean it's a cache-miss?

1

There are 1 best solutions below

0
coleifer On BEST ANSWER

I've already activated the peewee query logging. If a query is logged there, does it mean it's a cache-miss?

Yes.

The row-cache only caches rows so that multiple iterations over the same query result will not result in multiple executions.

Example:

q = User.select()
# Query is executed:
for user in q:
    print(user.email)

# Query is **not** re-executed.
for user in q:
    print(user.email)

q2 = User.select()
# Query is executed:
for user in q2:
    print(user.email)