Gathering detailed insights and metrics for @pietal.dev/cache
Gathering detailed insights and metrics for @pietal.dev/cache
Gathering detailed insights and metrics for @pietal.dev/cache
Gathering detailed insights and metrics for @pietal.dev/cache
simple, zero-dependency, in-memory, lazy cache for javascript
npm install @pietal.dev/cache
Typescript
Module System
Node Version
NPM Version
JavaScript (63.27%)
TypeScript (36.73%)
Total Downloads
3,188
Last Day
3
Last Week
121
Last Month
280
Last Year
2,918
2 Stars
28 Commits
2 Watchers
1 Branches
1 Contributors
Updated on May 23, 2024
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
@pietal.dev/cache@2.0.2
Unpacked Size
8.59 kB
Size
2.96 kB
File Count
6
NPM Version
10.7.0
Node Version
18.20.3
Published on
May 23, 2024
Cumulative downloads
Total Downloads
Last Day
-84.2%
3
Compared to previous day
Last Week
112.3%
121
Compared to previous week
Last Month
-31.5%
280
Compared to previous month
Last Year
980.7%
2,918
Compared to previous year
2
You know when you were a kid and mom told you to clean your room,
when you was busy with something else, your answer would always be the same: 'later, mom'.
This library is the universal 0 dependencies lazy cache implementation,
leveraging usage of es6 data structures.
yarn add @pietal.dev/cache --save
1const { Cache } = require("@pietal.dev/cache") 2 3const maxSize = 2 // will limit max cache size upon cache.get() 4const getUser = async (id) => { 5 const response = await fetch("https://dummyjson.com/users/" + id) 6 const { firstName, lastName, address } = await response.json() 7 8 return { 9 id, 10 name: `${firstName} ${lastName}`, 11 address, 12 } 13} 14 15const usersCached = new Cache(getUser, maxSize) 16 17Promise.all([ 18 usersCached.get(1), 19 usersCached.get(2), 20 usersCached.get(3), 21 usersCached.get(4), 22]).then((users) => { 23 console.log(usersCached.data) // contains only last maxSize users (3 and 4) 24 console.log(usersCached.size) // 2 25})
1const { Cache } = require("@pietal.dev/cache") 2// create cache with factory function (may take any number of parameters) 3const cache = new Cache(() => Math.random()) 4 5// each time you call the cache.get with same parameters 6// you will get the same once lazy cached answer 7const a = cache.get(1, 2, 3) 8const b = cache.get(1, 2, 3) // this will return the same as above 9const c = cache.get(1, 2) 10const d = cache.get(1, 2, 4) 11 12console.log(a === b) // true 13console.log(a !== c) // true 14console.log(a !== d) // true
1class Cache<T = unknown> { 2 constructor(factoryFunction: (...args: any[]) => T, maxSize: number = Infinity) { 3 // 4 } 5}
methods
get(...args: any[]): T
- get entry at key created from args, lazy instantiated by factorycreateKey(...args: any[]): string
- creates string keycreate(...args: any[]): T
- wrapped factory functionhasKey(key: string): boolean
- check if has entry at keyhas(...args: any[]): boolean
- check if has entry at key created from argsdeleteKey(key: string): boolean
- deletes entry from data at keydelete(...args): boolean
- deletes entry from data at key created from argssize: number
- returns size of datamaxSize: number
- on insert the oldest items are deleted until reached maxSizeproperties:
1$ jest 2 PASS ./index.test.js 3 ✓ Calls factory once when asked for same key many times (62 ms) 4 ✓ Getter is able to handle multiple arguments 5 ✓ Readme has working code (1 ms) 6 7Test Suites: 1 passed, 1 total 8Tests: 3 passed, 3 total 9Snapshots: 0 total 10Time: 0.946 s, estimated 1 s 11Ran all test suites. 12Done in 1.44s.
MIT
Jacek Pietal @ 2019-2021
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
7 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More