Gathering detailed insights and metrics for @alexsasharegan/simple-cache
Gathering detailed insights and metrics for @alexsasharegan/simple-cache
Gathering detailed insights and metrics for @alexsasharegan/simple-cache
Gathering detailed insights and metrics for @alexsasharegan/simple-cache
A basic key value store with bounded capacity for simple caching.
npm install @alexsasharegan/simple-cache
Typescript
Module System
Node Version
NPM Version
TypeScript (98.95%)
JavaScript (1.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
36 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Feb 28, 2022
Latest Version
3.3.3
Package Id
@alexsasharegan/simple-cache@3.3.3
Unpacked Size
52.77 kB
Size
10.18 kB
File Count
39
NPM Version
6.4.1
Node Version
10.15.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
A basic key value store with bounded capacity for simple caching.
1npm install @alexsasharegan/simple-cache
Visit the API Documentation here.
Cache is an interface for caching key/value pairs of types K
/V
. It's primary
functionality includes:
Cache.write
: write a value at a keyCache.read
: read a value from a keyCache.get
: read a value as an Option<V>
(maybe type)Cache.remove
: remove a value by keyCache.clear
: empty the cacheCreating a cache looks like this in plain JavaScript:
1// Creates a cache with a capacity of 10 items. The second parameter is the
2// "type label". It serves as a convenience option for more meaningful
3// `toString` behavior.
4let userCache = SimpleCache(10, { key: "ID", value: "User" })
5userCache.toString()
6// SimpleCache<ID, User> { size: 0, capacity: 10 }
If you're using TypeScript, you need to create a cache by declaring the key and value types as generic parameters:
1interface User { 2 id: number 3 name: string 4} 5 6let userCache = SimpleCache<number, User>(10, { key: "ID", value: "User" }) 7userCache.toString() 8// SimpleCache<ID, User> { size: 0, capacity: 10 }
Here are some examples of the five main interaction methods shown in REPL style.
If you're curious to learn more about the Option
type returned from
Cache.get
, visit the
safe-types repository.
1let userA = { name: "User A", id: 1 } 2let userB = { name: "User B", id: 2 } 3 4userCache.write(userA.id, userA) 5userCache.write(userB.id, userB) 6userCache.size() 7// 2 8 9userCache.read(1) 10// { name: "User A", id: 1 } 11userCache.read(2) 12// { name: "User B", id: 2 } 13userCache.get(2) 14// Some<{ name: "User B", id: 2 }> 15userCache.read(3) 16// undefined 17userCache.get(3) 18// None 19 20userCache.remove(1) 21userCache.size() 22// 1 23userCache.read(1) 24// undefined 25userCache.clear() 26userCache.size() 27// 0
There is an Ephemeral Cache available. It caches items for a duration that's given in milliseconds.
1// Sets a capacity of 10 users and a max lifetime of 5 seconds 2let userCache = EphemeralCache<number, User>(10, 5000, { 3 key: "ID", 4 value: "User", 5}) 6 7userCache.write(1, { name: "Temp", id: 1 }) 8 9setTimeout(() => { 10 userCache.read(1) 11 // undefined 12}, 5001) 13 14userCache.read(1) 15// { name: "Temp", id: 1 }
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
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
branch protection not enabled on development/release branches
Details
Reason
71 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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