gabriel-rusu / ngx-utils

Angular(TypeScript) library that contains reusable services like CacheService for browser caching either in session or local storage and a HttpCacheClient (a HttpClient wrapper that caches the results for speed improvements)

Home Page:https://www.npmjs.com/package/ngx-caching

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project logo

ngx-utils

License

Angular library that enables developer accessible browser caching by providing a CacheService and a HttpCacheService.

πŸ“ Table of Contents

🧐 About

This Angular library provides two services:

  • CacheService: which interacts directly with the browser local/session storage
  • HttpCacheService: which is a wrapper(decorator) around Angular HttpClient that offers the ability to cache any request that you want to (including post request) and offers the results as a Observable of the desired type, exactly as HttpClient.

🏁 Getting Started

To use this library you should have at least Angular 13. Installation of this library can be done using the following commands, depending on your package manager.

  • npm: npm i ngx-caching
  • yarn yarn add ngx-caching

🎈 Usage

The following is a basic usage example of the HttpCacheService:

...
import {HttpCacheService} from "ngx-caching";
...

constructor(private configService: ConfigService, private httpCached: HttpCacheService) { }

getValuesByType(typeId: number):Observable<any> {
 return this.httpCached.get(this.configService.getPath('dictionary', 'entries', {typeId}));
}

In the above example, the values that will be retrieved will also be cached, so any subsequent subscription to this method will result in a cache look-up rather than another HTTP request.

⛏️ Built Using

✍️ Authors

About

Angular(TypeScript) library that contains reusable services like CacheService for browser caching either in session or local storage and a HttpCacheClient (a HttpClient wrapper that caches the results for speed improvements)

https://www.npmjs.com/package/ngx-caching

License:MIT License


Languages

Language:TypeScript 73.3%Language:JavaScript 26.7%