@javien/mikro-orm-redis-cache-adapter
Advanced tools
Comparing version 0.0.9 to 0.0.10
{ | ||
"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" | ||
] | ||
} |
# 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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
11531
8
90
0
8
64
1