Skip to content

Commit

Permalink
updating documentation and version (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Apr 4, 2024
1 parent b03c2ad commit 4adb2b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
1 change: 1 addition & 0 deletions src/caching.ts
Expand Up @@ -133,6 +133,7 @@ export function createCache<S extends Store, C extends Config>(
.then(async result => store.set<T>(key, result, cacheTtl))
.catch(async error => {
eventEmitter.emit('error', error);
eventEmitter.emit('onBackgroundRefreshError', error);
if (arguments_?.onBackgroundRefreshError) {
arguments_.onBackgroundRefreshError(error);
} else {
Expand Down

0 comments on commit 4adb2b1

Please sign in to comment.