Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@javien/mikro-orm-redis-cache-adapter

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@javien/mikro-orm-redis-cache-adapter - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

dist/index.cjs

38

package.json
{
"name": "@javien/mikro-orm-redis-cache-adapter",
"description": "mikro-orm redis cache adapter using v8 serialize",
"version": "0.0.10",
"license": "MIT",
"description": "",
"version": "0.0.9",
"author": "Javien Lee <kraccoon@dimipay.io> (https://github.com/SnowMarble/)",
"keywords": ["mikro-orm", "redis", "cache", "adapter"],
"homepage": "https://github.com/SnowMarble/mikro-orm-redis-cache-adapter",
"repository": {
"type": "git",
"url": "git+https://github.com/SnowMarble/mikro-orm-redis-cache-adapter.git"
},
"keywords": [
"mikro-orm",
"redis",
"cache",
"adapter"
],
"main": "dist/index.js",
"module": "dist/index.js",
"typings": "dist/index.d.ts",
"exports": {
".": {
"import": {
"default": "./dist/index.mjs"
},
"require": {
"default": "./dist/index.cjs"
},
"types": "./dist/index.d.ts"
}
},
"type": "module",

@@ -15,6 +36,11 @@ "scripts": {

"check:apply": "biome check --apply src",
"build": "rm -rf dist && esbuild src/index.ts --bundle --platform=node --outdir=dist& tsc --emitDeclarationOnly --outdir dist"
"bundle": "esbuild src/index.ts --bundle --platform=node --minify",
"bundle:cjs": "pnpm bundle --outfile=dist/index.cjs --format=cjs",
"bundle:esm": "pnpm bundle --outfile=dist/index.mjs --format=esm",
"emitDeclarations": "tsc --emitDeclarationOnly --outdir dist",
"build": "rm -rf dist && pnpm \"/^bundle:.+$/\" && pnpm emitDeclarations"
},
"devDependencies": {
"@biomejs/biome": "1.7.3",
"@changesets/cli": "^2.27.3",
"@mikro-orm/core": "^6.2.8",

@@ -27,3 +53,5 @@ "@types/node": "^20.12.12",

},
"files": ["dist"]
"files": [
"dist"
]
}

50

README.md
# Mikro ORM Redis Cache Adapter
This is mikro orm redis cache adapter that uses `v8.serialize` and
`vs.deserialize` rather than `JSON.stringify` and `JSON.parse`.
`v8.deserialize` rather than `JSON.stringify` and `JSON.parse`.
## Quick start
## Quick Start
After install the package, add `resultCache` config.
After install the package, edit your `resultCache` configuration.
```typescript
import
RedisCacheAdapter,
{ type RedisCacheAdapterOptions}
from '@javien/mikro-orm-redis-cache-adapter'
import { RedisCacheAdapter, type RedisCacheAdapterOptions} from '@javien/mikro-orm-redis-cache-adapter'

@@ -30,5 +27,5 @@ defineConfig({

// (optional) Logger. Defaults to `console.log`.
logger: 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) gracefulShutdown: If you want to close the Redis connection by yourself, set it to `false`. Defaults to `true`.
} as RedisCacheAdapterOptions

@@ -39,6 +36,35 @@ }

## Behavior Explained
- Failing to store cache, it'll log the error regardless of the debug mode.
- Failing to fetch cache, `undefined` will be returned, which means your data will be loaded from the database.
- Failing to delete the cache, it'll log the error regardless of the debug mode.
## Debug Mode
If you use debug mode, saving data is shown with `JSON.stringify` applied.
it doesn't mean `JSON.stringify` is used to serialize the data. It's only for logging purposes.
## Supported Data Types
`v8.serialize` is compatible with [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), so only [Supported types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types) are able to get serialized.
Here're suported JavaScript types.
- Array, ArrayBuffer, and TypedArray
- Number, String, and Boolean
- Primitive types, except symbol.
- DataView
- Date
- Error types (see more at MDN page).
- Map and Set
- Object objects: but only plain objects (e.g. from object literals).
- RegExp: but note that lastIndex is not preserved.
If your property is not supported type, consider using [Custom Type](https://mikro-orm.io/docs/custom-types).
## Why not JSON.stringify?
[`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) is usually used to serialize object,
but there're several kind of data that it can't serialize and deserialize - BigInt, recursive, Buffer, Map, Set and etc.
[`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.

@@ -65,2 +91,2 @@ ```js

To solve this, we can pass [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter) parameter. However I thought this is not a best way to serialize data.
To solve this, we can pass the [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter) parameter. However, I don't think this is the best way to serialize data, while we can choose v8 api.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc