-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fifo-cache): fix remove implementation, update docs
- Loading branch information
Showing
6 changed files
with
136 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
interface IFifoCache { | ||
get size(): number; | ||
set capacity(value: number); | ||
read: (key: any) => any; | ||
store: (key: any, value: any) => void; | ||
has: (key: any) => boolean; | ||
clear: () => void; | ||
} | ||
type TConfigOptions = { | ||
import { ICache } from '../libs/types.js'; | ||
declare class FifoCache implements ICache { | ||
#private; | ||
constructor(capacity: number); | ||
get stats(): { | ||
size: number; | ||
capacity: number; | ||
locked: boolean; | ||
hitRatio: number; | ||
}; | ||
set lock(state: boolean); | ||
/** | ||
* Capacity means how many items can be stored at the same time in cache. | ||
* For FIFO cache, by definition, capacity is a required restriction, | ||
* without it becomes almost meaningless, so this option is mandatory. | ||
* Read value stored in cache by assosiated key. | ||
* @param {*} key - cache record's key | ||
* @return {*|void} record's value retrieved by key or undefined if record is absent | ||
*/ | ||
capacity: number; | ||
}; | ||
declare class FifoCache implements IFifoCache { | ||
#private; | ||
constructor(options: TConfigOptions); | ||
get size(): number; | ||
set capacity(value: number); | ||
read(key: any): any; | ||
store(key: any, value: any): void; | ||
add(key: any, value: any): void; | ||
/** | ||
* Check if record by given key exists in cache. | ||
* @param {*} key - cache record's key | ||
* @return {boolean} return true if record is in the cache | ||
*/ | ||
has(key: any): boolean; | ||
/** | ||
* Remove an item from the cache. | ||
* @param {*} key - cache record's key | ||
* @return {void} | ||
*/ | ||
remove(key: any): void; | ||
/** | ||
* Remove all items from the cache and clear internal structures. | ||
* @return {void} | ||
*/ | ||
clear(): void; | ||
} | ||
export default FifoCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters