
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@javien/mikro-orm-redis-cache-adapter
Advanced tools
mikro-orm redis cache adapter using v8 serialize
This is mikro orm redis cache adapter that uses v8.serialize
and
v8.deserialize
rather than JSON.stringify
and JSON.parse
.
After install the package, edit your resultCache
configuration.
import { RedisCacheAdapter, type RedisCacheAdapterOptions} from '@javien/mikro-orm-redis-cache-adapter'
defineConfig({
// your configuration
resultCache: {
adapter: RedisCacheAdapter
options: {
// pass your redis client
client: redis
// (optional) Debug mode. Defaults to `false`.
debug: true,
// (optional) The prefix for the cache keys. Defaults to `mikro`.
prefix: 'mikro',
// (optional) The delimiter between the prefix and the cache key. Defaults to `:`.
prefixDelimiter: ':',
// (optional) Logger. Defaults to `console.log`.
logger: myLogger,
// (optional) gracefulShutdown: If you want to close the Redis connection by yourself,
// set it to `false`. Defaults to `true`.
gracefulShutdown: false,
// (optional) maximumCacheBytes: The maximum cache size of each key in bytes. Defaults to `-1`.
maximumCacheBytes: 1024 * 1024,
// (optional) base64Encode: If you want to use base64 encoding, set it to `true`. Defaults to `false`.
base64Encode: false
} as RedisCacheAdapterOptions
}
})
undefined
will be returned, which means your data will be loaded from the database.v8.serialize
is compatible with The structured clone algorithm, so only Supported types are able to get serialized.
Here're suported JavaScript types.
If your property is not supported type, consider using Custom Type.
JSON.stringify
is usually used to serialize objects,
but there are several kinds of data that it can't serialize and deserialize - BigInt, recursive, Buffer, Map, Set, etc.
JSON.stringify(BigInt(1))
// Uncaught TypeError: Do not know how to serialize a BigInt
JSON.stringify(new Date()) // '"2024-05-26T05:39:00.493Z"'
// serializes to string, so parsed result is different from original
const buf = Buffer.from([0])
const str = JSON.stringify(buf) //'{"type":"Buffer","data":[0]}'
// Buffer.toJSON method is called, so parsed result is different from original
To solve this, we can pass the replacer
parameter.
So you might think using JSON.stringify
with replacer
is fine.
However, I don't think this is the best way to serialize data, while we can choose v8 api.
FAQs
mikro-orm redis cache adapter using v8 serialize
The npm package @javien/mikro-orm-redis-cache-adapter receives a total of 11 weekly downloads. As such, @javien/mikro-orm-redis-cache-adapter popularity was classified as not popular.
We found that @javien/mikro-orm-redis-cache-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.