From 1b9a1bc8a3be72c2430a716e3668659b100942cc Mon Sep 17 00:00:00 2001 From: vinicius Date: Sat, 14 Sep 2024 23:46:52 -0300 Subject: [PATCH] make some params optional / fix some docs / add alias for delAll() --- package.json | 2 +- src/caches/cache.ts | 11 +++++------ src/caches/pool.ts | 2 +- src/caches/ttl.ts | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8e77d16..f0ce470 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cachetools-js", - "version": "1.0.0", + "version": "1.0.1", "description": "Best, faster, ligther, all-in-one, fully-typed cache library for JS, based on cachetools from python, with events, pooling and decorators.", "author": "vinikjkkj", "license": "MIT", diff --git a/src/caches/cache.ts b/src/caches/cache.ts index e2ac9a5..c0aca57 100644 --- a/src/caches/cache.ts +++ b/src/caches/cache.ts @@ -19,11 +19,6 @@ import { CacheParams, Keyable } from '../types' * * //get 'bar' key * cache['bar'] - * - * //try to store another key - * cache['baz'] = 'foo' - * //throws SizeError, you need to delete some key to store another key - * * ``` */ export class Cache extends CacheEmitter { @@ -35,7 +30,7 @@ export class Cache extends CacheEmitter { /** * Creates a new Cache. */ - constructor(params: CacheParams){ + constructor(params: CacheParams = {}){ super() this._cache = new Map() this._params = params @@ -90,6 +85,10 @@ export class Cache extends CacheEmitter { this._cache.delete(key) } + flushAll(){ + this.delAll() + } + delAll(){ this._cache.clear() } diff --git a/src/caches/pool.ts b/src/caches/pool.ts index ad2cdf9..3e7b832 100644 --- a/src/caches/pool.ts +++ b/src/caches/pool.ts @@ -31,7 +31,7 @@ export class CachePool extends CachePoolEmitter { [key: string | symbol]: unknown - constructor(params: CachePoolParams){ + constructor(params: CachePoolParams = {}){ super() this._caches = new Map() this._params = params diff --git a/src/caches/ttl.ts b/src/caches/ttl.ts index df2bff9..107abb1 100644 --- a/src/caches/ttl.ts +++ b/src/caches/ttl.ts @@ -35,7 +35,7 @@ export class TTLCache extends Cache { /** * Creates a new TTLCache. */ - constructor(params: TTLParams){ + constructor(params: TTLParams = {}){ super({ maxsize: params.maxsize, useClones: params.useClones