
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
@hitorisensei/memoizee-decorator
Advanced tools
Memoization decorator backed by memoizee and hash-sum
Adds memoization decorator for methods and getters.
Uses memoizee library for memoization.
Uses hash-sum library as a default cache-key generation algorithm.
import { Memoize } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize()
public getMyValue(): number {
console.log('My value is calculated');
return someExpensiveCalculation();
}
}
const myClass = new MyClass();
myClass.getMyValue(); // console logs 'My value is calculated' only once
myClass.getMyValue(); // returns cached value
Decorator can be called with all memoizee options.
import { Memoize } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize({
maxAge: 1000,
max: 100,
})
public getMyValue(): number {
console.log('My value is calculated');
return someExpensiveCalculation();
}
}
import { Memoize, clearMemoization } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize()
public getMyValue(): number {
console.log('My value is calculated');
return someExpensiveCalculation();
}
}
const myClass = new MyClass();
myClass.getMyValue(); // console logs 'My value is calculated' only once
myClass.getMyValue(); // returns cached value
clearMemoization(myClass, 'getMyValue'); // clears cache
myClass.getMyValue(); // console logs 'My value is calculated' again
By default, memoization cache key is generated based on the function arguments using hash-sum library.
So the memoization cache will be shared between calls with the same arguments, but not between calls with different arguments.
import { Memoize } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize()
public getMyValue(value: number): number {
console.log('My value is calculated for', value);
return someExpensiveCalculation(value);
}
}
const myClass = new MyClass();
myClass.getMyValue(1); // console logs 'My value is calculated for 1' only once
myClass.getMyValue(1); // returns cached value
myClass.getMyValue(2); // logs 'My value is calculated for 2'
myClass.getMyValue(2); // returns cached value
If you want to limit the number of cached results, e.g. when the function can be called with a large number of different arguments, you can use the max option.
import { Memoize } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize({
max: 3,
})
public getMyValue(value: number): number {
console.log('My value is calculated for', value);
return someExpensiveCalculation(value);
}
}
const myClass = new MyClass();
myClass.getMyValue(1); // logs 'My value is calculated for 1'
myClass.getMyValue(2); // logs 'My value is calculated for 2'
myClass.getMyValue(3); // logs 'My value is calculated for 3'
myClass.getMyValue(4); // logs 'My value is calculated for 4'
// LRUCache with max 3, so only 3 last results are cached
myClass.getMyValue(2); // returns cached value for 2
myClass.getMyValue(3); // returns cached value for 3
myClass.getMyValue(4); // returns cached value for 4
myClass.getMyValue(1); // logs 'My value is calculated for 1'
By default, the parameters are hashed with hash-sum.
If you want to use custom cache key generation algorithm, you can pass a normalizer function to the decorator.
import { Memoize } from '@hitorisensei/memoizee-decorator';
class MyClass {
@Memoize({
normalizer: (args: any[]) => args[0].toString(),
})
public getMyValue(value: number): number {
console.log('My value is calculated');
return someExpensiveCalculation(value);
}
}
FAQs
Memoization decorator backed by memoizee and hash-sum
We found that @hitorisensei/memoizee-decorator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.