npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-dedup

v0.0.9

Published

<h1 align="center">ngx-dedup</h1>

Downloads

10

Readme

Introduction

Many components in an Angular app need to use the same data. With ngx-dedup you do not have to fetch data globally, nor forward it via input properties. Instead you can fetch data within your components without worrying about the performance implications of making multiple requests for the same data. ngx-dedup intercepts all requests and automatically deduplicates requests based on the URL and options.

How is this different from a caching library?

With the default configurations ngx-dedup only caches requests based on the current active route path. This way your data stays up to date during navigation but different components never cause a duplicated request.

Install

npm i ngx-dedup

Usage

To use ngx-dedup, add the NgxDedupModule to your imports in your app.module.ts. and include the DedupInterceptor in the providers array.

import { NgxDedupModule } from "ngx-dedup";

@NgModule({
  imports: [NgxDedupModule.forRoot()], //Add to your imports
  bootstrap: [AppComponent],
})
export class AppModule {}

With this minimal setup all GET request are deduplicated.

Configuration

You can pass a configuration object via forRoot(). Please see the list below for all config options.

 NgxDedupModule.forRoot({
      isRouteBased: true,
      isLoggingEnabled: false,
      maxAge: 10000,
      maxChacheSize: 100,
      isCachable: (request: HttpRequest<any>) => request.method === 'GET'
 }),

| Property | Default Value | Description | | :--------: | :-------------: | :------------: | | isRouteBased | true | If set to true requests are only deduplicated on the current active route path | | isLoggingEnabled | false | If set to true all interactions within NgxDebug are logged to the console | | maxAge | undefined | Sets the maximum caching age in milliseconds. By default requests have no maxAge. | | maxCacheSize | 100 | Limits the number of cachable items | | isCachable | request.method === 'GET' | By default all GET requests are cachable. Use custom logic to overwrite this behavior |

Skip the cache for certain requests

If you want certain requests to skip the cache (e.g. to force a refresh of your data), you can set the NGX_DEDUP_SKIP_CACHE token of the HttpContext to true


const context = new HttpContext().set(NGX_DEDUP_SKIP_CACHE, true);
this.http.get('https://swapi.dev/api/people/1', { context });

Remove certain requests from cache

To remove specific requests from cache, inject the NgxDedupService in your constructor and call the removeFromCache() method. Pass the requests URL + queryParams as the key.


constructor(private _ngxDedupService: NgxDedupService) { }

someMethod(): void {
  this._ngxDedupService.removeFromCache('https://swapi.dev/api/people/1');
}

Remove all requests from cache

To remove all requests from cache, inject the NgxDedupService in your constructor and call the clearCache() method.


constructor(private _ngxDedupService: NgxDedupService) { }

someMethod(): void {
  this._ngxDedupService.clearCache();
}