@javien/mikro-orm-redis-cache-adapter
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -5,3 +5,3 @@ { | ||
"description": "", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": "Javien Lee <kraccoon@dimipay.io> (https://github.com/SnowMarble/)", | ||
@@ -8,0 +8,0 @@ "keywords": ["mikro-orm", "redis", "cache", "adapter"], |
@@ -6,4 +6,59 @@ # Mikro ORM Redis Cache Adapter | ||
## Quick start | ||
After install the package, add `resultCache` config. | ||
```typescript | ||
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: console.log, | ||
gracefulShutdown: false | ||
// (optional) gracefulShutdown: If you want to close the Redis connection by yourself, set it to `false`. Defaults to `true`. | ||
} as RedisCacheAdapterOptions | ||
} | ||
}) | ||
``` | ||
## Why not JSON.stringify? | ||
`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. | ||
```js | ||
JSON.stringify(BigInt(1)) | ||
// Uncaught TypeError: Do not know how to serialize a BigInt | ||
const obj = {} | ||
obj.obj = obj | ||
JSON.stringify(obj) | ||
// Uncaught TypeError: Converting circular structure to JSON | ||
// --> starting at object with constructor 'Object' | ||
// --- property 'obj' closes the circle | ||
const buf = Buffer.from([0]) | ||
const str = JSON.stringify(buf) | ||
// '{"type":"Buffer","data":[0]}' | ||
const parsed = JSON.parse(str) | ||
// { type: 'Buffer', data: [ 0 ] } | ||
// parsed value is different with original data. | ||
``` | ||
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. |
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
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
9948
64