Question: what happens with caching when using DSL alongside DAO
- Dominant language
- Kotlin
- Stars
- 9.3k
- Forks
- 798
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 26
Description
Hi!
Recently I stumbled upon the same problem as described in https://github.com/JetBrains/Exposed/issues/914, where I have to upsert a value ([using this library](https://github.com/PerfectDreams/ExposedPowerUtils/blob/6004dc905372378d2297c3d19a51e091b9ad18e2/postgres-power-utils/src/main/kotlin/net/perfectdreams/exposedpowerutils/sql/upsert.kt#L22)) and then retrieve it by calling `Entity.findById` - it returns cached entity with outdated values. I've solved that by calling `Entity.removeFromCache` after doing an upsert, but that got me thinking
How safe is it to be using DSL queries alongside DAO? Is entity cache somehow updated/invalidated when DSL queries are performed?
In other words, if I update an entity without explicitly committing/flushing, and then call some service which performs a DSL query to find this entity - will I see the updated value? Not necessarily interested in this particular case, but in similar cases in general, where you have a mix of DSL/DAO operations within the same transaction
Should I stick to DSL only if I want to avoid possible cache-related problems?
Asking because DAO API is not as flexible, so I have to be doing DSL queries in between.
Contributor guide
Research direction
Read the linked issue #914 and the referenced upsert.kt example first; then trace Entity.findById, Entity.removeFromCache, and mixed DSL/DAO calls within one transaction. Done would require a documented, verified answer about cache invalidation and visibility of uncommitted updates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- database
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100