Skip to content

Commit

Permalink
fix: add missing options on core methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Nov 11, 2023
1 parent 0c06621 commit c3373d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions src/bento_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type {
DeleteOptions,
SetOptions,
BentoCachePlugin,
HasOptions,
ClearOptions,
} from './types/main.js'

export class BentoCache<KnownCaches extends Record<string, BentoStore>> implements CacheProvider {
Expand Down Expand Up @@ -170,15 +172,15 @@ export class BentoCache<KnownCaches extends Record<string, BentoStore>> implemen
/**
* Check if a key exists in the cache
*/
async has(key: string) {
return this.use().has(key)
async has(key: string, options?: HasOptions) {
return this.use().has(key, options)
}

/**
* Check if key is missing in the cache
*/
async missing(key: string) {
return this.use().missing(key)
async missing(key: string, options?: HasOptions) {
return this.use().missing(key, options)
}

/**
Expand Down Expand Up @@ -208,15 +210,15 @@ export class BentoCache<KnownCaches extends Record<string, BentoStore>> implemen
/**
* Remove all items from the cache
*/
async clear() {
return this.use().clear()
async clear(options?: ClearOptions) {
return this.use().clear(options)
}

/**
* Remove all items from all caches
*/
async clearAll() {
await Promise.all(Object.keys(this.#stores).map((cache) => this.use(cache).clear()))
async clearAll(options?: ClearOptions) {
await Promise.all(Object.keys(this.#stores).map((cache) => this.use(cache).clear(options)))
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export class Cache implements CacheProvider {
/**
* Check if key is missing in the cache
*/
async missing(key: string) {
return !(await this.has(key))
async missing(key: string, options?: HasOptions) {
return !(await this.has(key, options))
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ export interface CacheProvider {
*/
getOrSetForever<T>(key: string, cb: Factory<T>, opts?: GetOrSetOptions): Promise<T>

/**
* Check if a key is missing from the cache
*/
missing(key: string): Promise<boolean>

/**
* Returns a new instance of the driver namespaced
*/
Expand All @@ -75,6 +70,11 @@ export interface CacheProvider {
*/
has(key: string, options?: HasOptions): Promise<boolean>

/**
* Check if a key is missing from the cache
*/
missing(key: string, options?: HasOptions): Promise<boolean>

/**
* Get the value of a key and delete it
*
Expand Down

0 comments on commit c3373d7

Please sign in to comment.