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

ngxj-http-cache

v0.0.2

Published

This is a translator that does translation.

Downloads

3

Readme

NgxHttpCache

NgxHttpCache is a utility library for Angular that provides caching functionality. It uses the power of IndexDB to store and retrieve the data.

Static Badge GitHub Repo stars GitHub package.json version (branch)

Usage

1. Install

npm install ngx-http-cache --save --dev

2. Service Integration

Integrate NgxHttpCacheService into your Angular application:

import { Injectable } from '@angular/core';
import { IndexedDBUtil } from './IndexedDBUtil';

@Injectable({
  providedIn: 'root'
})
export class NgxHttpCacheService<T> {
  private util = new IndexedDBUtil<T>();

  async setStore(objectStoreName: string, keyPath: string, expiryTime: number): Promise<void> {
    this.util.setObjectStoreName(objectStoreName, keyPath, expiryTime).then();
  }

  getAll(): Promise<T[]> {
    return this.util.getAll();
  }

  addItems(payload: T[]): void {
    this.util.addItems(payload);
  }

  addItem(item: T): void {
    this.util.addItem(item);
  }

  getItem(id: number): void {
    this.util.getItem(id);
  }

  delete(id: number): void {
    this.util.delete(id);
  }

  update(item: T): void {
    this.util.update(item);
  }
}

consuming the library to your application

import {Component, DestroyRef, inject, OnInit, signal} from '@angular/core';
import {NgxHttpCacheService} from "../../../../../ngx-http-cache/src/lib/ngx-http-cache.service";
import {ApiService} from "../../services/api.service";
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {Product} from "../../models/product";
import {ProductComponent} from "./product.component";
import {RouterLink} from "@angular/router";
import {EXPIRY_TIME} from "../games-list/games-list.component";

@Component({
  selector: 'products-list',
  standalone: true,
  imports: [
    ProductComponent,
    RouterLink
  ],
  template: `
    @defer () {
      <div class="bg-body-tertiary border border-1 border-primary rounded d-flex justify-content-between">
        <h2 class="text-primary m-2">Product List</h2>
        <a class="btn btn-outline-primary m-2" routerLink="/games">Games</a>
      </div>
      <div class="row">
        <button class="btn btn-outline-primary m-2" (click)="addProduct()">Add Product</button>
        @for (product of products(); track product.id) {
          <div class="col-md-4">
            <product [product]="product"/>
          </div>
        }
      </div>
    } @loading () {
      <h4>loading...</h4>
    }`,
  styles: ``
})
export class ProductsListComponent implements OnInit {
  private readonly ngxHttpCacheService = inject(NgxHttpCacheService);
  private readonly apiService = inject(ApiService);
  private readonly destroyRef = inject(DestroyRef);
  products = signal<Product[]>([]);

  ngOnInit(): void {
    this.setStore();
    this.getCache();
  }

  async setStore() {
    await this.ngxHttpCacheService.setStore('products', 'id', EXPIRY_TIME);
  }

  getCache(): void {
    this.ngxHttpCacheService.getAll().then((products) => {
      if (products.length === 0) {
        this.getProducts();
      } else {
        this.products.set(products);
      }
    });
  }

  getProducts() {
    this.apiService.getProducts()
      .pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
      next: response => {
        if (response) {
          this.products.set(response);
          this.setStore();
          this.ngxHttpCacheService.addItems(this.products());
        }
      },
      error: err => {
        console.log('ERROR: ', err);
      }
    });
  }

  addProduct() {
    const item =
      {id: 3332, title: 'TEST 2', discountedPrice: 55.99, price: 49.95, quantity: 100}
    this.ngxHttpCacheService.addItem(item);
  }
}

The NgxHttpCacheService class is a service in your library that provides a high-level API for interacting with IndexedDB. It uses the IndexedDBUtil class to perform operations on the database. Here’s a more detailed description of the NgxHttpCacheService class and its methods:

  • util: This private property holds an instance of the IndexedDBUtil class. It’s used internally by the service to perform operations on the database.
  • setStore(objectStoreName: string, keyPath: string, expiryTime: number): This asynchronous method sets the object store name and key path, and the expiry time for the database. It calls the setObjectStoreName method of the IndexedDBUtil instance.
  • getAll(): This method retrieves all items from the object store. It returns a promise that resolves with the items. It calls the getAll method of the IndexedDBUtil instance.
  • addItems(payload: T[]): This method adds multiple items to the object store. It calls the addItems method of the IndexedDBUtil instance.
  • addItem(item: T): This method adds a single item to the object store. It calls the addItem method of the IndexedDBUtil instance.
  • getItem(id: number): This method retrieves an item from the object store by its id. It calls the getItem method of the IndexedDBUtil instance.
  • delete(id: number): This method deletes an item from the object store by its id. It calls the delete method of the IndexedDBUtil instance.
  • update(item: T): This method updates an item in the object store. It calls the update method of the IndexedDBUtil instance.

The NgxHttpCacheService class is decorated with the @Injectable decorator, which means it can be provided and injected as a dependency in other parts of your Angular application. The { providedIn: 'root' } configuration means that the service is provided in the root injector and is available throughout the app.

This service provides a convenient way to interact with IndexedDB by abstracting away some of the complexities of the IndexedDB API. It can be used to store, retrieve, update, and delete items in the database. The generic parameter T allows you to use this service with any type of data that you want to store in the database.

In summary, your library provides a set of tools for managing data in IndexedDB, making it easier for developers to use this powerful browser API. It includes features for setting up the database and object stores, checking for expiry, and performing CRUD operations. It’s a useful tool for any web application that needs to handle large amounts of data locally.

Troubleshooting

Please follow this guidelines when reporting bugs and feature requests:

  1. Use GitHub Issues board to report bugs and feature requests (not our email address)
  2. Please always write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.

Thanks for understanding!

License

The MIT License (see the LICENSE file for the full text)