
Research
/Security News
Coruna Respawned: Compromised art-template npm Package Leads to iOS Browser Exploit Kit
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.
@pietal.dev/cache
Advanced tools
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
const { Cache } = require("@pietal.dev/cache")
const maxSize = 2 // will limit max cache size upon cache.get()
const getUser = async (id) => {
const response = await fetch("https://dummyjson.com/users/" + id)
const { firstName, lastName, address } = await response.json()
return {
id,
name: `${firstName} ${lastName}`,
address,
}
}
const usersCached = new Cache(getUser, maxSize)
Promise.all([
usersCached.get(1),
usersCached.get(2),
usersCached.get(3),
usersCached.get(4),
]).then((users) => {
console.log(usersCached.data) // contains only last maxSize users (3 and 4)
console.log(usersCached.size) // 2
})
const { Cache } = require("@pietal.dev/cache")
// create cache with factory function (may take any number of parameters)
const cache = new Cache(() => Math.random())
// each time you call the cache.get with same parameters
// you will get the same once lazy cached answer
const a = cache.get(1, 2, 3)
const b = cache.get(1, 2, 3) // this will return the same as above
const c = cache.get(1, 2)
const d = cache.get(1, 2, 4)
console.log(a === b) // true
console.log(a !== c) // true
console.log(a !== d) // true
class Cache<T = unknown> {
constructor(factoryFunction: (...args: any[]) => T, maxSize: number = Infinity) {
//
}
}
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:
$ jest
PASS ./index.test.js
✓ Calls factory once when asked for same key many times (62 ms)
✓ Getter is able to handle multiple arguments
✓ Readme has working code (1 ms)
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 0.946 s, estimated 1 s
Ran all test suites.
Done in 1.44s.
MIT
Jacek Pietal @ 2019-2021
FAQs
simple, zero-dependency, in-memory, lazy cache for javascript
The npm package @pietal.dev/cache receives a total of 8 weekly downloads. As such, @pietal.dev/cache popularity was classified as not popular.
We found that @pietal.dev/cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Compromised npm package art-template delivered a Coruna-like iOS Safari exploit framework through a watering-hole attack.

Company News
As AI accelerates how code is written and shipped, Socket is scaling to protect the software supply chain from the growing wave of attacks targeting open source dependencies.

Company News
Socket is scaling to defend open source against supply chain attacks as AI accelerates software development.