Skip to content

Commit 5ff4806

Browse files
committed
feat: do not cache queries that are part of a transaction
1 parent 8eb2744 commit 5ff4806

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Query cache interceptor is initialised using a custom storage service. The [Exam
1414

1515
Which queries are cached is controlled using cache attributes. Cache attributes are comments starting with `-- @cache-` prefix. Only queries with cache attributes are cached (see [Cache attributes](#cache-attributes))
1616

17+
## Behavior
18+
19+
* Does not cache queries inside of a transaction
20+
1721
## Cache attributes
1822

1923
|Cache attribute|Description|Required?|Default|

src/factories/createQueryCacheInterceptor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export const createQueryCacheInterceptor = (configurationInput: ConfigurationInp
4545

4646
return {
4747
beforeQueryExecution: async (context, query) => {
48+
if (context.transactionId) {
49+
return null;
50+
}
51+
4852
const cacheAttributes = (context.sandbox as Sandbox).cache?.cacheAttributes;
4953

5054
if (!cacheAttributes) {
@@ -64,6 +68,10 @@ export const createQueryCacheInterceptor = (configurationInput: ConfigurationInp
6468
return null;
6569
},
6670
beforeQueryResult: async (context, query, result) => {
71+
if (context.transactionId) {
72+
return null;
73+
}
74+
6775
const cacheAttributes = (context.sandbox as Sandbox).cache?.cacheAttributes;
6876

6977
if (cacheAttributes) {
@@ -73,6 +81,10 @@ export const createQueryCacheInterceptor = (configurationInput: ConfigurationInp
7381
return null;
7482
},
7583
beforeTransformQuery: async (context, query) => {
84+
if (context.transactionId) {
85+
return null;
86+
}
87+
7688
const cacheAttributes = extractCacheAttributes(query.sql);
7789

7890
if (!cacheAttributes) {

0 commit comments

Comments
 (0)