Skip to content

Commit 90d82fd

Browse files
committed
fixed cache issue
1 parent bca22cb commit 90d82fd

File tree

37 files changed

+4060
-3857
lines changed

37 files changed

+4060
-3857
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ const rawUsers = await forgeSQL.execute(
359359
);
360360

361361
// Raw SQL with caching
362+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names must be wrapped with backticks (`)
362363
const cachedRawUsers = await forgeSQL.executeCacheable(
363-
"SELECT * FROM users WHERE active = ?",
364+
"SELECT * FROM `users` WHERE active = ?",
364365
[true],
365366
300
366367
);
@@ -480,8 +481,9 @@ const rawUsers = await forgeSQL.execute(
480481
);
481482

482483
// Raw SQL with caching
484+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names must be wrapped with backticks (`)
483485
const cachedRawUsers = await forgeSQL.executeCacheable(
484-
"SELECT * FROM users WHERE active = ?",
486+
"SELECT * FROM `users` WHERE active = ?",
485487
[true],
486488
300
487489
);
@@ -616,6 +618,9 @@ Please review the [official @forge/kvs quotas and limits](https://developer.atla
616618
- Monitor cache usage to stay within quotas
617619
- Use appropriate TTL values
618620

621+
**⚠️ Important Cache Limitations:**
622+
- **Table names starting with `a_`**: Tables whose names start with `a_` (case-insensitive) are automatically ignored in cache operations. KVS Cache will not work with such tables, and they will be excluded from cache invalidation and cache key generation.
623+
619624
### Step 1: Install Dependencies
620625

621626
```bash
@@ -1135,8 +1140,10 @@ const user = await forgeSQL
11351140
.execute("SELECT * FROM users WHERE id = ?", [1]);
11361141

11371142
// Using forgeSQL.executeCacheable() - Execute raw SQL with local and global caching
1143+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names in SQL queries must be wrapped with backticks (`)
1144+
// Example: SELECT * FROM `users` WHERE id = ? (NOT: SELECT * FROM users WHERE id = ?)
11381145
const user = await forgeSQL
1139-
.executeCacheable("SELECT * FROM users WHERE id = ?", [1], 300);
1146+
.executeCacheable("SELECT * FROM `users` WHERE id = ?", [1], 300);
11401147

11411148
// Using forgeSQL.getDrizzleQueryBuilder()
11421149
const user = await forgeSQL
@@ -1265,8 +1272,10 @@ const users = await forgeSQL
12651272
.execute("SELECT * FROM users WHERE active = ?", [true]);
12661273

12671274
// Using executeCacheable() for raw SQL with local and global caching
1275+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names in SQL queries must be wrapped with backticks (`)
1276+
// Example: SELECT * FROM `users` WHERE active = ? (NOT: SELECT * FROM users WHERE active = ?)
12681277
const users = await forgeSQL
1269-
.executeCacheable("SELECT * FROM users WHERE active = ?", [true], 300);
1278+
.executeCacheable("SELECT * FROM `users` WHERE active = ?", [true], 300);
12701279

12711280
// Using executeWithMetadata() for capturing execution metrics and performance monitoring
12721281
const usersWithMetadata = await forgeSQL.executeWithMetadata(
@@ -1759,8 +1768,9 @@ await forgeSQL.executeWithLocalContext(async () => {
17591768
.where(eq(users.active, true));
17601769

17611770
// Raw SQL with multi-level caching
1771+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names must be wrapped with backticks (`)
17621772
const rawUsers = await forgeSQL.executeCacheable(
1763-
"SELECT id, name FROM users WHERE active = ?",
1773+
"SELECT id, name FROM `users` WHERE active = ?",
17641774
[true],
17651775
300 // TTL in seconds
17661776
);
@@ -1809,8 +1819,9 @@ const usersDistinct = await forgeSQL.selectDistinctCacheableFrom(Users)
18091819
.where(eq(Users.active, true));
18101820

18111821
// Raw SQL with local and global caching
1822+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names must be wrapped with backticks (`)
18121823
const rawUsers = await forgeSQL.executeCacheable(
1813-
"SELECT * FROM users WHERE active = ?",
1824+
"SELECT * FROM `users` WHERE active = ?",
18141825
[true],
18151826
300 // TTL in seconds
18161827
);
@@ -2503,8 +2514,9 @@ const rawUsers = await forgeSQL.execute(
25032514
[true]
25042515
);
25052516

2517+
// ⚠️ IMPORTANT: When using executeCacheable(), all table names must be wrapped with backticks (`)
25062518
const cachedRawUsers = await forgeSQL.executeCacheable(
2507-
"SELECT * FROM users WHERE active = ?",
2519+
"SELECT * FROM `users` WHERE active = ?",
25082520
[true],
25092521
300
25102522
);

0 commit comments

Comments
 (0)