You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/docs/cache_drivers.md
+4-1
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,8 @@ const bento = new BentoCache({
98
98
default: 'memory',
99
99
stores: {
100
100
memory: bentostore().useL1Layer(memoryDriver({
101
-
maxSize: 10*1024*1024,
101
+
maxSize: '10mb',
102
+
maxEntrySize: '1mb',
102
103
maxItems: 1000
103
104
}))
104
105
}
@@ -111,6 +112,8 @@ const bento = new BentoCache({
111
112
|`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 |
112
113
|`maxEntrySize`| The maximum size of a single entry in bytes. | N/A |
113
114
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
+
114
117
## DynamoDB
115
118
116
119
DynamoDB is also supported by bentocache. You will need to install `@aws-sdk/client-dynamodb` to use this driver.
Copy file name to clipboardexpand all lines: docs/content/docs/grace_periods.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -64,4 +64,4 @@ bento.getOrSet({
64
64
})
65
65
```
66
66
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.
Copy file name to clipboardexpand all lines: docs/content/docs/introduction.md
+1-2
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ Bentocache is a robust multi-tier caching library for Node.js applications
12
12
- 🔄 Synchronization of local cache via Bus
13
13
- 🚀 Many drivers (Redis, Upstash, In-memory, Postgres, Sqlite and others)
14
14
- 🛡️ Grace period and timeouts. Serve stale data when the store is dead or slow
15
+
- 🤓 SWR-like caching strategy
15
16
- 🗂️ Namespaces. Group your keys by categories.
16
17
- 🛑 Cache stamped protection.
17
18
- 🏷️ Named caches
@@ -28,8 +29,6 @@ Not to knock them, on the contrary, they have their use cases and cool. Some are
28
29
29
30
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.
30
31
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
-
33
32
## Quick presentation
34
33
35
34
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 :
Copy file name to clipboardexpand all lines: docs/content/docs/options.md
+24-3
Original file line number
Diff line number
Diff line change
@@ -63,14 +63,16 @@ The TTL of the item to cache. See [TTL formats](#ttl-formats).
63
63
64
64
### `suppressL2Errors`
65
65
66
-
Default: `false`
66
+
Default: `true` if L1 and L2 Caches are enabled. `false` if only L2 Cache is enabled.
67
67
68
68
Levels: `global`, `store`, `operation`
69
69
70
70
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.
71
71
72
72
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.
73
73
74
+
Note that event if errors are suppressed and not thrown, they will still be logged if you have a logger configured.
75
+
74
76
### `grace`
75
77
76
78
Default `undefined`
@@ -89,10 +91,10 @@ A duration to define the [grace backoff](./grace_periods.md).
89
91
90
92
### `timeout`
91
93
92
-
Default: `undefined`
94
+
Default: `0`
93
95
Levels: `global`, `store`, `operation`
94
96
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.
96
98
97
99
### `hardTimeout`
98
100
@@ -111,6 +113,25 @@ The maximum amount of time (in milliseconds) that the in-memory lock for [stampe
111
113
112
114
This is usually not needed, but can provide an extra layer of protection against theoretical deadlocks.
113
115
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 =newBentoCache({
124
+
default: 'memory',
125
+
onFactoryError: (error) => {
126
+
console.error('Factory error', error, 'when trying to fetch for key', error.key)
0 commit comments