diff --git a/README.md b/README.md index 65b4acd7..2258f763 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,19 @@ A cache module for nodejs that allows easy wrapping of functions in cache, tiered caches, and a consistent interface. +## Table of Contents +* [Features](#features) +* [Installation](#installation) +* [Usage Examples](#usage-examples) + * [Single Store](#single-store) + * [Multi-Store](#multi-store) + * [Cache Manager Options](#cache-manager-options) + * [Refresh cache keys in background](#refresh-cache-keys-in-background) + * [Error Handling](#error-handling) + * [Store Engines](#store-engines) +* [Contribute](#contribute) +* [License](#license) + ## Features - Made with Typescript and compatible with [ESModules](https://nodejs.org/docs/latest-v14.x/api/esm.html) @@ -204,6 +217,22 @@ const memoryCache = await caching('memory', { When a value will be retrieved from Redis with a TTL minor than 3sec, the value will be updated in the background. +## Error Handling + +Cache Manager now does not throw errors by default. Instead, all errors are evented through the `error` event. Here is an example on how to use it: + +```javascript +const memoryCache = await caching('memory', { + max: 100, + ttl: 10 * 1000 /*milliseconds*/, +}); +memoryCache.on('error', (error) => { + console.error('Cache error:', error); +}); +``` + +We also have added + ## Store Engines ### Official and updated to last version diff --git a/package.json b/package.json index fe03b075..f4cd9cad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cache-manager", - "version": "5.4.0", + "version": "5.5.0", "description": "Cache module for Node.js", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/caching.ts b/src/caching.ts index 0c7e8edb..de575ac8 100644 --- a/src/caching.ts +++ b/src/caching.ts @@ -133,6 +133,7 @@ export function createCache( .then(async result => store.set(key, result, cacheTtl)) .catch(async error => { eventEmitter.emit('error', error); + eventEmitter.emit('onBackgroundRefreshError', error); if (arguments_?.onBackgroundRefreshError) { arguments_.onBackgroundRefreshError(error); } else {