Skip to content

Commit d836c83

Browse files
committed
docs: minor things
1 parent 5c4480e commit d836c83

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

docs/content/docs/cache_drivers.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ const bento = new BentoCache({
9898
default: 'memory',
9999
stores: {
100100
memory: bentostore().useL1Layer(memoryDriver({
101-
maxSize: 10 * 1024 * 1024,
101+
maxSize: '10mb',
102+
maxEntrySize: '1mb',
102103
maxItems: 1000
103104
}))
104105
}
@@ -111,6 +112,8 @@ const bento = new BentoCache({
111112
| `maxItems` | The maximum number of entries that the cache can contain. Note that fewer items may be stored if you are also using `maxSize` and the cache is full. | N/A |
112113
| `maxEntrySize` | The maximum size of a single entry in bytes. | N/A |
113114

115+
`maxSize` and `maxEntrySize` accept human-readable strings. We use [bytes](https://www.npmjs.com/package/bytes) under the hood so make sure to ensure the format is correct. A `number` can also be passed to these options.
116+
114117
## DynamoDB
115118

116119
DynamoDB is also supported by bentocache. You will need to install `@aws-sdk/client-dynamodb` to use this driver.

docs/content/docs/grace_periods.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ bento.getOrSet({
6464
})
6565
```
6666

67-
In this example, if the factory fails, we will wait 5 minutes before trying again.
67+
In this example, if the factory fails, we will wait 5 minutes before trying again. In other words, we will extend the `ttl` of the cache entry by 5 minutes, so BentoCache will not try to call the factory again and again.

docs/content/docs/introduction.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bentocache is a robust multi-tier caching library for Node.js applications
1212
- 🔄 Synchronization of local cache via Bus
1313
- 🚀 Many drivers (Redis, Upstash, In-memory, Postgres, Sqlite and others)
1414
- 🛡️ Grace period and timeouts. Serve stale data when the store is dead or slow
15+
- 🤓 SWR-like caching strategy
1516
- 🗂️ Namespaces. Group your keys by categories.
1617
- 🛑 Cache stamped protection.
1718
- 🏷️ Named caches
@@ -28,8 +29,6 @@ Not to knock them, on the contrary, they have their use cases and cool. Some are
2829

2930
Bentocache, on the other hand, is a **full-featured caching library**. We indeed have this notion of unified access to different drivers, but in addition to that, we have a ton of features that will allow you to do robust caching.
3031

31-
With that in mind, then I believe there is no serious alternative to Bentocache in the JavaScript ecosystem. Which is regrettable, because all other languages have powerful solutions. This is why Bentocache was created.
32-
3332
## Quick presentation
3433

3534
Bentocache is a caching solution aimed at combining performance and flexibility. If you are looking for a caching system that can transition from basic use to advanced multi-level configuration, you are in the right place. Here's what you need to know :

docs/content/docs/options.md

+24-3
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ The TTL of the item to cache. See [TTL formats](#ttl-formats).
6363

6464
### `suppressL2Errors`
6565

66-
Default: `false`
66+
Default: `true` if L1 and L2 Caches are enabled. `false` if only L2 Cache is enabled.
6767

6868
Levels: `global`, `store`, `operation`
6969

7070
If `false`, then errors thrown by your L2 cache will be rethrown, and you will have to handle them yourself. Otherwise, they will just be ignored.
7171

7272
Note that in some cases, like when you use [Grace Periods](./grace_periods.md), errors will not be thrown, even if this option is set to `false`. Since this is the whole point of grace periods.
7373

74+
Note that event if errors are suppressed and not thrown, they will still be logged if you have a logger configured.
75+
7476
### `grace`
7577

7678
Default `undefined`
@@ -89,10 +91,10 @@ A duration to define the [grace backoff](./grace_periods.md).
8991

9092
### `timeout`
9193

92-
Default: `undefined`
94+
Default: `0`
9395
Levels: `global`, `store`, `operation`
9496

95-
A duration to define a soft [timeout](./timeouts.md#soft-timeouts).
97+
A duration to define a soft [timeout](./timeouts.md#soft-timeouts). By default, this is `0`, which means : if we have a stale value in cache, we will return it immediately, and start a background refresh.
9698

9799
### `hardTimeout`
98100

@@ -111,6 +113,25 @@ The maximum amount of time (in milliseconds) that the in-memory lock for [stampe
111113

112114
This is usually not needed, but can provide an extra layer of protection against theoretical deadlocks.
113115

116+
### `onFactoryError`
117+
118+
Default: `undefined`
119+
120+
A function that will be called when a factory, running in background or not, throws an error. This can be useful for logging or monitoring purposes.
121+
122+
```ts
123+
const bento = new BentoCache({
124+
default: 'memory',
125+
onFactoryError: (error) => {
126+
console.error('Factory error', error, 'when trying to fetch for key', error.key)
127+
console.log(error.isBackground)
128+
}
129+
stores: {
130+
memory: bentostore().useL1Layer(memoryDriver({})),
131+
},
132+
})
133+
```
134+
114135
### `serializer`
115136

116137
Default: `JSON.stringify` and `JSON.parse`

0 commit comments

Comments
 (0)