Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@merry-solutions/memoize-decorator
Advanced tools
A function to decorate methods and memoize their results to speed up further requests done with the same arguments.
A function to decorate methods and memoize their results to speed up further requests done with the same arguments.
npm i @merry-solutions/memoize-decorator
The decorator can accept the following payload:
export interface MemoizePayload {
// The function that will determine a unique id for the provided arguments set, you write iy
extractUniqueId: (...args: any[]) => any;
// Pass true if you want to use WeakMap, not that it requires keys to be objects
doUseWeakMap?: boolean;
// If regular map is used, you can set timeout to clear its contents, optional
clearCacheTimeout?: number;
// For debug purposes you can pass an exta function for logging all actions
debugReporter?: (message: string, state?: Map<any, unknown> | WeakMap<object, unknown> | unknown) => void;
}
Now let's assume there's some class doing some calculations:
interface CalculationPayload {
id: number;
someCountdownNumber: number;
}
class ObjectCountdownCalculator {
public countdown({ someCountdownNumber }: CalculationPayload): number {
let count = 0;
while (count < someCountdownNumber) {
count += 1;
}
return count;
}
}
Assuming the unique arguments' identifier is the id of the passed object, we could decorate it:
import { memoize } from '@merry-solutions/memoize-decorator';
class ObjectCountdownCalculator {
@memoize({
extractUniqueId: (a: CalculationPayload) => a.id,
})
public countdown({ someCountdownNumber }: CalculationPayload): number {
let count = 0;
while (count < someCountdownNumber) {
count += 1;
}
return count;
}
}
And poof! Our method is now leveraging the power of memoization to reduce execution time :)
FAQs
A function to decorate methods and memoize their results to speed up further requests done with the same arguments.
We found that @merry-solutions/memoize-decorator 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.