@devon4ng/cache

11.0.1 • Public • Published

Cache Module

Use this devon4ng Angular module when you want to cache requests to server. You may configure it to store in cache only the requests you need and to set the duration you want.

Installation

$ npm i object-hash @devon4ng/cache

Or you can use yarn:

$ yarn add object-hash @devon4ng/cache

To install the correct vesion for your Angular project please refer to the @devon4ng/cache versions available.

Usage

Import the dependency in your app.module.ts:

import { CacheModule } from '@devon4ng/cache';

Import and configure it in the @NgModule imports section:

@NgModule({
  ...
  imports: [
    ...otherModules,
    CacheModule.forRoot({
      maxCacheAge: 1800000, // number
      urlRegExp: new RegExp('http.*', 'g').toString(); // RegExp object or string
    }),
  ]
})

In case you need to define a list of strings instead, you can do the following:

@NgModule({
  ...
  imports: [
    ...otherModules,
    CacheModule.forRoot({
      maxCacheAge: 1800000, // number
      urlRegExp: ['data', 'users']; // strings array
    }),
  ]
})

The configuration object defines the following two parameters:

  • maxCacheAge: Age in milliseconds. After that the cache entry will be developed. By default 1800000 or 30 minutes.
  • urlRegExp: Regular expression as string, string[] or RegExp object that defines which URLs are going to be cached. By default any URL that contains http, that is all the URLs.

Both parameters are optional, so you could set up only one.

Versions

Current Tags

Version History

Package Sidebar

Install

npm i @devon4ng/cache

Weekly Downloads

0

Version

11.0.1

License

Apache-2.0

Unpacked Size

12.7 kB

Total Files

19

Last publish

Collaborators

  • sjimenez77
  • rgarciam
  • jsrubio
  • mmatczak