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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mdfrough/ngx-smart-cache

v0.0.3

Published

Smart targeted cache layer for Angular HttpClient with TTL and tagging support.

Downloads

15

Readme

🔥 @mdfrough/ngx-smart-cache

A lightweight, flexible caching layer for Angular HttpClient — with full support for standalone APIs and NgModules.

npm version Angular License


✨ Features

  • ✅ TTL-based per-request caching
  • 🔁 In-memory cache for fast re-use of HTTP responses
  • 🏷 Tag-based cache invalidation
  • 🚫 Easily skip cache on-demand
  • 🚀 Works with both HttpInterceptorFn (Angular 15+) and HTTP_INTERCEPTORS for older apps

📦 Installation

npm install @mdfrough/ngx-smart-cache

🚀 Quick Start

✅ Enable the Interceptor

Option A: Standalone App (Angular 15+)

import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { cacheInterceptor } from '@mdfrough/ngx-smart-cache';

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(withFetch(), withInterceptors([cacheInterceptor]))
  ]
});

Option B: NgModule App

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { CacheInterceptor } from '@mdfrough/ngx-smart-cache';

@NgModule({
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: CacheInterceptor, multi: true }
  ]
})
export class AppModule {}

🧠 Caching Requests with withCache()

import { withCache } from '@mdfrough/ngx-smart-cache';

this.http.get('/api/products', {
  context: withCache({
    ttl: 60000,       // cache for 60 seconds
    tag: 'products',  // optional group tag
  })
}).subscribe(data => {
  console.log('Loaded:', data);
});

❌ Skip Caching on Specific Calls

this.http.get('/api/users', {
  context: withCache({ skip: true })
});

🧹 Invalidate Cache Manually

import { CacheService } from '@mdfrough/ngx-smart-cache';

constructor(private cacheService: CacheService) {}

clearProductsCache() {
  this.cacheService.invalidateByTag('products');
}

⚙️ API Reference

withCache(options)

| Option | Type | Description | |----------|----------|----------------------------------------------| | ttl | number | Time to live (ms) — how long to cache | | tag | string | Optional tag for manual group invalidation | | skip | boolean| Bypass cache and fetch fresh data |


🧱 How It Works

  • Wraps Angular's HttpClient with a smart interceptor
  • Uses HttpContext to control per-request behavior
  • Stores cached responses in memory using a TTL expiration strategy
  • Compatible with Angular 15+ (both module and standalone styles)

📌 Angular Compatibility

| Angular Version | Support Type | |------------------|--------------------| | 15+ | ✅ Fully Supported | | 14 and below | ⚠️ Use class interceptor only (no HttpInterceptorFn) |


🧪 Example

ngOnInit() {
  this.loadData();
}

loadData() {
  this.http.get('https://dummyjson.com/products', {
    context: withCache({ ttl: 60000, tag: 'products' })
  }).subscribe(data => console.log('Loaded:', data));
}

🧱 Architecture

HttpClient ➜ cacheInterceptor ➜ HttpBackend
             ▲         |
             |         ▼
         CacheService <➜> In-Memory Store (Map)

🧪 Roadmap

  • [ ] LocalStorage / IndexedDB support
  • [ ] Global cache policy (e.g. network-first, stale-while-revalidate)
  • [ ] Observable cache invalidation (RxJS-based)

🛡 License

MIT © MDFrough


🙌 Contributions

PRs and issues welcome! Let’s build faster Angular apps together 🚀