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
It means that, the data stored in the memory cache will not be serialized/parsed using `JSON.stringify` and `JSON.parse`. This allows for a much faster throughput but at the expense of:
8
+
- not being able to limit the size of the stored data, because we can't really know the size of an unserialized object
9
+
- Having inconsistent return between the L1 and L2 cache. The data stored in the L2 Cache will always be serialized because it passes over the network. Therefore, depending on whether the data is retrieved from the L1 and L2, we can have data that does not have the same form. For example, a Date instance will become a string if retrieved from the L2, but will remain a Date instance if retrieved from the L1. So, you should put extra care when using this feature with an additional L2 cache.
Copy file name to clipboardExpand all lines: docs/content/docs/cache_drivers.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,9 +111,19 @@ const bento = new BentoCache({
111
111
|`maxSize`| The maximum size of the cache **in bytes**. | N/A |
112
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 |
113
113
|`maxEntrySize`| The maximum size of a single entry in bytes. | N/A |
114
+
|`serialize`| If the data stored in the memory cache should be serialized/parsed using `JSON.stringify` and `JSON.parse`. |`true`|
114
115
115
116
`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
117
118
+
### `serialize` option
119
+
120
+
By default, the data stored in the memory cache will always be serialized using `JSON.stringify` and `JSON.parse`.
121
+
You can disable this feature by setting `serialize` to `false`. This allows for a much faster throughput but at the expense of:
122
+
- not being able to limit the size of the stored data, because we can't really know the size of an unserialized object. So if `maxSize` or `maxEntrySize` is set, it throws an error, but you still can use `maxItems` option.
123
+
-**Having inconsistent return between the L1 and L2 cache**. The data stored in the L2 Cache will always be serialized because it passes over the network. Therefore, depending on whether the data is retrieved from the L1 and L2, we can have data that does not have the same form. For example, a Date instance will become a string if retrieved from the L2, but will remain a Date instance if retrieved from the L1. So, **you should put extra care when using this feature with an additional L2 cache**.
124
+
125
+
We recommend never storing anything that is not serializable in the memory cache when an L2 cache is used ( `Date`, `Map`, classes instances, functions etc.. ). However, if you are only using the memory cache, it is safe to store anything you.
126
+
117
127
## DynamoDB
118
128
119
129
DynamoDB is also supported by bentocache. You will need to install `@aws-sdk/client-dynamodb` to use this driver.
0 commit comments