-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue description
alwaysEnabled by definition "If set to true then queries (using find methods and QueryBuilder's methods) will always be cached." should cache the query without explicitly stating 'cache: true' or 'cache: false'. However, version 0.3.12, when alwaysEnabled=true and cache is not defined in query, the result is not cached.
Expected Behavior
While alwaysEnabled is set to true
- cache (in query) = false, result should NOT be cached
- cache (in query) = true, result should be cached
- cache (in query) = undefined, whether the result should be cached should depend on global value
alwaysEnabled
Actual Behavior
When alwaysEnabled=true and cache is not defined in query, the result is not cached.
Steps to reproduce
- Set the global
alwaysEnabledtotrue - Do not set the
cachein query - Run the query by using
findOne(or otherfind*)
My Environment
| Dependency | Version |
|---|---|
| Operating System | MacOS 13.2.1 |
| Node.js version | 18.10 |
| Typescript version | 4.9.5 |
| TypeORM version | 0.3.12 |
Additional Context
The issue seems coming from recent change that trying to fix issue #9023 (https://github.com/typeorm/typeorm/pull/9731/files)
However, it does not consider the case when this.expressionMap.cache is undefined in cacheOptions.alwaysEnabled && this.expressionMap.cache. Only this.expressionMap.cache is false should override the global setting in this specific query.

This is my interoperation, and please feel to correct me.
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
I am willing to help but I may not have enough time to understand the background and fix it correctly. Anyone from the community would be appreciated.