Registry / storage / ionic-cache

ionic-cache

JSON →
library6.0.3jsnpmunverified

Ionic Cache is a caching service for Angular/Ionic apps that caches HTTP requests, observables, promises, and plain data. Version 6.0.3 is current. It uses Ionic Storage (IndexedDB, SQLite, WebSQL) as the backing store and supports configurable TTL, group invalidation, offline resilience, and delayed observable caching. It ships TypeScript types and requires @angular/common >=9.0.0, @angular/core >=9.0.0, and @ionic/storage-angular >=3 as peer dependencies. Key differentiators: tight Ionic/Angular integration, delayed observable pattern for seamless stale-while-revalidate behavior.

npm install ionic-cache
INSTALL
IMPORT
SIG · IONIC-CACHE
I
ionic-cache
storagejavascriptv6.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CacheService
import { CacheService } from 'ionic-cache'
import CacheService from 'ionic-cache'
Named export, not default. The library ships TypeScript types.
CacheModule
import { CacheModule } from 'ionic-cache'
import { CacheModule } from '@ionic/cache'
CacheModule is for root import. Common mistake to use wrong package path.
CacheRequestOptions
import { CacheRequestOptions } from 'ionic-cache'
Type export for configuring request caching options. Available since v4.

Shows full Angular module setup with CacheModule.forRoot and ionic-storage-angular, then basic HTTP request caching using CacheService.loadFromObservable.

import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; import { IonicStorageModule } from '@ionic/storage-angular'; import { CacheModule, CacheService } from 'ionic-cache'; import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, HttpClientModule, IonicStorageModule.forRoot(), CacheModule.forRoot({ keyPrefix: 'my-app-cache' }) ], bootstrap: [AppComponent] }) export class AppModule { } // In a component/service: import { Component } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-root', template: '' }) export class AppComponent { constructor(private http: HttpClient, private cache: CacheService) { this.cache.setDefaultTTL(60 * 60); // 1 hour const url = 'https://api.example.com/data'; const request = this.http.get(url); this.cache.loadFromObservable('data-key', request).subscribe(data => { console.log('Cached data:', data); }); } }
Debug
Known issues
breakingclearAll() clears Ionic Storage entirely if no keyPrefix is set.
fix
Set a keyPrefix in CacheModule.forRoot({ keyPrefix: 'my-app-cache' }) to scope cache entries.
affects: >=3.0.0
deprecatedCacheModule.forRoot() without any arguments is deprecated.
fix
Pass a config object even if empty: CacheModule.forRoot({}).
affects: >=4.0.0
gotchaloadFromObservable returns cached data immediately and does NOT refetch in background; use loadFromDelayedObservable for stale-while-revalidate.
fix
For background refresh, use cache.loadFromDelayedObservable(cacheKey, request, group, ttl, 'all') instead.
affects: >=1.0.0
breakingAngular 9+ required; older versions of Angular not supported.
fix
Upgrade to Angular 9 or later.
affects: >=6.0.0
gotchaCache keys must be unique per entry; collisions overwrite silently.
fix
Use descriptive, unique cache keys (e.g., URLs with query parameters).
affects: >=1.0.0
deprecatedThe 'delayType' parameter in loadFromDelayedObservable is deprecated in favor of a single config object.
fix
Use the new signature: loadFromDelayedObservable(key, request, options) where options includes delayType.
affects: >=5.0.0
Errors
Common errors & fixes
Error: Can't resolve '@ionic/storage-angular' in '...'
Missing peer dependency @ionic/storage-angular.
fix
Run: npm install @ionic/storage-angular (or yarn add @ionic/storage-angular).
Attempted to load from observable but no key provided
Calling loadFromObservable with empty or undefined cacheKey.
fix
Always provide a non-empty string as the first argument to loadFromObservable.
TypeError: Cannot read property 'get' of undefined
Ionic Storage not initialized before CacheService usage.
fix
Ensure IonicStorageModule.forRoot() is imported in AppModule, and CacheService is used after app initialization.
Data: [object Object]
JSON response not parsed; cache returns raw string.
fix
Use HttpClient from '@angular/common/http' which auto-parses JSON. If using plain fetch, parse manually.
Upgrade
Version history
6.0.3latest on npm
Audit
Dependencies
@ionic/storage-angularrequiredRequired as the underlying storage engine for cache persistence.
@angular/corerequiredAngular peer dependency for injection and module system.
@angular/commonrequiredAngular peer dependency for common Angular utilities.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
ionic-cache — npm install ionic-cache · libregistry