AngularCacheable
An angular library for cacheing your method responses using decorators Compatible with Angular 9+
Installation
Install it with npm
npm install angular-cacheable --save
Migration from v0.0.4 to v0.1.1
Breaking changes in v0.1.1
-
Remove all
key
paramters fromCacheable
. Exmaple:@Cacheable({ key: 'posts' })
=>@Cacheable()
-
Default TTL is now 1 hour.
Usage example
- Add a
Cacheable
decorator to your method that returns anObservable
.
; // ... /** Basic usage */ public getCategories /** Specifing a TTL: 1 second */ public getCategories /** Custom key */ public getCategories /** Custom function key */ public getCategoriespage: number, other: string
To invalidate cache call
CacheableService.getInstance.invalidate yourCacheKey ;
Decorator parameters
Function Name | Description |
---|---|
key | A key for cache (must be unique) or a function that |
returns a key. Defaults to method name concatenated | |
with hashed arguments. | |
ttl | TTL in milliseconds, default 1 hour |
License
MIT © Evgeny Gushchin