Skip to content

Commit eb2258e

Browse files
committed
chore: release 1.2.0
1 parent 44d0be4 commit eb2258e

12 files changed

Lines changed: 127 additions & 143 deletions

.changeset/cyan-ladybugs-build.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

.changeset/funny-books-refuse.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

.changeset/good-candles-trade.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

.changeset/hip-cameras-kneel.md

Lines changed: 0 additions & 28 deletions
This file was deleted.

.changeset/khaki-days-clean.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/rich-mugs-prove.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

.changeset/stupid-moose-care.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

.changeset/tasty-shirts-judge.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/hono/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"dependencies": {
88
"@hono/node-server": "^1.13.8",
9-
"bentocache": "^1.1.0",
9+
"bentocache": "^1.2.0",
1010
"hono": "^4.7.1"
1111
},
1212
"devDependencies": {

packages/bentocache/CHANGELOG.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,129 @@
11
# bentocache
22

3+
## 1.2.0
4+
5+
### Minor Changes
6+
7+
- 8bb87b6: Add a new `expire` method.
8+
9+
This method is slightly different from `delete`:
10+
11+
When we delete a key, it is completely removed and forgotten. This means that even if we use grace periods, the value will no longer be available.
12+
13+
`expire` works like `delete`, except that instead of completely removing the value, we just mark it as expired but keep it for the grace period. For example:
14+
15+
```ts
16+
// Set a value with a grace period of 6 minutes
17+
await cache.set({
18+
key: 'hello',
19+
value: 'world',
20+
grace: '6m',
21+
})
22+
23+
// Expire the value. It is kept in the cache but marked as STALE for 6 minutes
24+
await cache.expire({ key: 'hello' })
25+
26+
// Here, a get with grace: false will return nothing, because the value is stale
27+
const r1 = await cache.get({ key: 'hello', grace: false })
28+
29+
// Here, a get with grace: true will return the value, because it is still within the grace period
30+
const r2 = await cache.get({ key: 'hello' })
31+
32+
assert.deepEqual(r1, undefined)
33+
assert.deepEqual(r2, 'world')
34+
```
35+
36+
- d513fe2: Add a new `E_L2_CACHE_ERROR`. Before this commit, error happening when interacting with the L2 cache were not wrapped in a custom error. This is now the case. If needed, you can still access the original error by using the `cause` property of the `E_L2_CACHE_ERROR` error.
37+
38+
```ts
39+
import { errors } from 'bentocache'
40+
41+
try {
42+
await cache.getOrSet({
43+
key: 'foo',
44+
factory: getFromDb(),
45+
})
46+
} catch (err) {
47+
if (err instanceof errors.E_L2_CACHE_ERROR) {
48+
console.error('An error happened while interacting with the L2 cache', err.cause)
49+
}
50+
}
51+
```
52+
53+
- 4d1feb5: Added a super simple circuit breaker system to the L2 Cache :
54+
55+
- a `l2CircuitBreakerDuration` parameter to set the duration of the circuit breaker. How many seconds the circuit breaker will stay open.
56+
- If defined, the circuit breaker will open when a call to our distributed cache fails. It will stay open for `l2CircuitBreakerDuration` seconds.
57+
58+
We may introduce more sophisticated circuit breaker system in the future, but for now, this simple system should be enough.
59+
60+
- 6b1f42a: Enhance Factory Context by adding some new props.
61+
62+
```ts
63+
await cache.getOrSet({
64+
key: 'foo',
65+
factory: (ctx) => {
66+
// You can access the graced entry, if any, from the context
67+
if (ctx.gracedEntry?.value === 'bar') {
68+
return 'foo'
69+
}
70+
71+
// You should now use `setOptions` to update cache entry options
72+
ctx.setOptions({
73+
tags: ['foo'],
74+
ttl: '2s',
75+
skipL2Write: true,
76+
})
77+
78+
return 'foo'
79+
},
80+
})
81+
```
82+
83+
`setTtl` has been deprecated in favor of `setOptions` and will be removed in the next major version.
84+
85+
- 73ac0fa: Add **experimental** tagging support. See https://github.com/Julien-R44/bentocache/issues/53
86+
87+
```ts
88+
await bento.getOrSet({
89+
key: 'foo',
90+
factory: getFromDb(),
91+
tags: ['tag-1', 'tag-2'],
92+
})
93+
94+
await bento.set({
95+
key: 'foo',
96+
tags: ['tag-1'],
97+
})
98+
```
99+
100+
Then, we can delete all entries tagged with tag-1 using:
101+
102+
```ts
103+
await bento.deleteByTags({ tags: ['tag-1'] })
104+
```
105+
106+
As this is a rather complex feature, let's consider it experimental for now. Please report any bugs on Github issues
107+
108+
- 6b1f42a: Add `skipL2Write` and `skipBusNotify` options.
109+
110+
```ts
111+
await cache.getOrSet({
112+
key: 'foo',
113+
skipL2Write: true,
114+
skipBusNotify: true,
115+
factory: () => 'foo',
116+
})
117+
```
118+
119+
When enabled, `skipL2Write` will prevent the entry from being written to L2 cache, and `skipBusNotify` will prevent any notification from being sent to the bus. You will probably never need to use these options, but they were useful for internal code, so decided to expose them.
120+
121+
- b9db3b5: Rework the logs issued by bentocache to make them much cleaner, more consistent and make debug easier
122+
123+
### Patch Changes
124+
125+
- 491d12e: Handle deleteMany with empty keys list
126+
3127
## 1.1.0
4128

5129
### Minor Changes

0 commit comments

Comments
 (0)