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

angular-function-cache

v0.0.2

Published

A library for handling cache events and operations in Angular applications.

Downloads

161

Readme

Angular Memoization Library

Overview

The Angular Memoization Library provides utilities and decorators to optimize performance by caching the results of expensive computations. This library allows you to easily implement memoization design patterns in your Angular applications.

Features

  • Memoization decorator for class methods.
  • Utility functions for manual memoization.
  • A service to manage and clear cache.
  • Compatible with Angular versions 8 to 18.

Installation

You can install the library via NPM:

npm install angular-cache

Using the Memoization Library

  • Once the library is installed, Angular developers can easily integrate it into their components and services.

  • Example 1: Using the Memoize Decorator in a Service - In a service, memoize a computationally expensive function using the Memoize decorator:

import { Injectable } from '@angular/core';
import { Memoize } from 'angular-cache';

@Injectable({
  providedIn: 'root'
})
export class ExpensiveCalculationService {

  @Memoize()
  calculateFactorial(n: number): number {
    if (n <= 1) return 1;
    return n * this.calculateFactorial(n - 1);
  }
}

In the above example, the calculateFactorial method is decorated with @Memoize(). If called with the same input, it will return the cached result.

  • Example 2: Using the MemoUtils Class - You can manually memoize a function using MemoUtils:
import { MemoUtils } from 'angular-cache';

export class SomeComponent {
  expensiveOperation = MemoUtils.memoize((a: number, b: number) => {
    // Simulate expensive computation
    return a + b;
  });

  run() {
    console.log(this.expensiveOperation(2, 3)); // Computes and caches
    console.log(this.expensiveOperation(2, 3)); // Retrieves from cache
  }
}
  • Example 3: Clearing Cache via Service - If you need to clear the memoization cache at any point in your app, you can use the MemoService:
import { MemoService } from 'angular-cache';

@Component({
  selector: 'app-some-component',
  template: `<button (click)="clearCache()">Clear Cache</button>`
})
export class SomeComponent {
  constructor(private memoService: MemoService) {}

  clearCache() {
    this.memoService.clearCache();
  }
}