Commit ded12c8
authored
Fix TTLCache.delete() to Align with get()/has() Behavior (#8153)
## Description
Fixes #8152
## Pillar
- [ ] π¨ Pillar 1 β New Theme Design
- [ ] π Pillar 2 β Geometric SVG Improvement
- [ ] π Pillar 3 β Timezone Logic Optimization
- [x] π οΈ Other (Bug fix, refactoring, docs)
## What this PR does
`get('')` and `has('')` are deliberately tested to return `null`/`false`
rather than throw (see existing tests in `lib/cache.test.ts`), but
`delete('')` still called the strict `assertValidKey()` helper and threw
a `TypeError` β untested, and inconsistent with the other two lookup-
style methods on the same class. This aligns `delete()` with the
already-
established `get()`/`has()` contract and removes the now-fully-dead
`assertValidKey()` helper and its leftover commented-out call sites.
## Changes
| File | Change |
|------|--------|
| `lib/cache.ts` | `delete()` returns `false` instead of throwing on an
invalid/empty key; removed dead `assertValidKey()` helper and 3 stray
commented-out call sites |
| `lib/cache.test.ts` | 3 new tests confirming `delete('')` no longer
throws and matches `has('')`/`get('')`, plus a normal-entry-removal
regression check |
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally.
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors.
- [x] My commits follow the Conventional Commits format.
- [x] I have made sure that I have only one commit to merge in this PR.3 files changed
Lines changed: 47 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
597 | 633 | | |
598 | 634 | | |
599 | 635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 59 | | |
70 | 60 | | |
71 | 61 | | |
| |||
210 | 200 | | |
211 | 201 | | |
212 | 202 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
217 | 208 | | |
218 | 209 | | |
219 | 210 | | |
| |||
0 commit comments