
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
ngx-cacheable
Advanced tools
Observable cache decorator you can use to decorate class methods which return streams and cache their return values.
To install the package, just run
npm install ngx-cacheable
Import the decorator from ngx-cacheable like:
import { Cacheable } from 'ngx-cacheable';
and use it decorate any class method like:
@Cacheable()
getUsers() {
return this.http
.get(`${environment.api}/users`);
}
Now all subsequent calls to this endpoint will be returned from an in-memory cache, rather than the actual http call! Another example will be:
@Cacheable()
getUser(id:string) {
return this.http
.get(`${environment.api}/users/${id}`);
}
If we call this method by service.getUser(1)
, its return value will be cached and returned, up until the method is called with a different parameter. Then the old cache will be busted and a new one will take its place.
For more information and other configurations, see the configuration options below
export interface ICacheConfig {
/**
* pass an Observable upon whose emission all caches will be busted
*/
cacheBusterObserver?: Observable<void>;
/**
* @description request cache resolver which will get old and new paramaters passed to and based on those
* will figure out if we need to bail out of cache or not
*/
cacheResolver?: ICacheRequestResolver;
/**
* @description cache decider that will figure out if the response should be cached or not, based on it
*/
shouldCacheDecider?: IShouldCacheDecider;
/**
* maxAge of cache in milliseconds
* @description if time between method calls is larger - we bail out of cache
*/
maxAge?: number;
/**
* whether should use a sliding expiration strategy on caches
* this will reset the cache created property and keep the cache alive for @param maxAge milliseconds more
*/
slidingExpiration?: boolean;
/**
* max cacheCount for different parameters
* @description maximum allowed unique caches (same parameters)
*/
maxCacheCount?: number;
/**
* cache will be resolved asynchronously - an extra change detection pass will be made by
* @description should cache be resolved asynchronously? - helps with declarative forms and two-way databinding via ngModel
*/
async?: boolean;
}
Just run npm test
.
The project is open for contributors! Please file an issue or make a PR:)
FAQs
Promise/Observable cache decorators
We found that ngx-cacheable 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.