@keyvhq/max-size
v2.2.2
Published
Prevents storing entries larger than a configured size in your Keyv instance.
Readme
@keyvhq/max-size
Prevents storing entries larger than a configured size.
Install
$ npm install @keyvhq/max-size --saveUsage
Wrap your store:
const KeyvRedis = require('@keyvhq/redis')
const KeyvMaxSize = require('@keyvhq/max-size')
const store = new KeyvMaxSize(
new KeyvRedis('redis://user:pass@localhost:6379'),
{ maxSize: 1024 * 1024 } // required
)Values larger than maxSize are skipped and .set() resolves to true, preserving default Keyv behavior for callers.
You can use it with bytes:
const bytes = require('bytes')
const store = new KeyvMaxSize(redisStore, {
maxSize: bytes('1KB')
})API
KeyvMaxSize(store, [options])
store
Type: object
Required: true
A store instance with a set method (e.g., KeyvRedis, Map).
options.maxSize
Type: number
Required: true
Maximum serialized entry size in bytes.
options.size
Type: (value, key) => number | Promise<number>
Default: internal byte length calculator
Custom byte size calculator.
options.onSkip
Type: (context) => void | Promise<void>
Hook executed when a key is skipped due to size limit.
License
@keyvhq/max-size © Kiko Beats, released under the MIT License. Maintained by Microlink with help from contributors.
microlink.io · GitHub microlinkhq · X @microlinkhq
