Registry / storage / ionic-file-cache

ionic-file-cache

JSON →
library2.0.48jsnpmunverified

Ionic cache service for files (images, videos, docs) that downloads and stores files in the device's local cache directory using Ionic Native File and File Transfer plugins. Latest version is 2.0.48, with infrequent releases. It provides a simple provider (`FileCacheProvider`) that wraps file caching with configurable TTL and enabling/disabling. Designed specifically for Ionic/Cordova apps, not for browser or React Native. Alternatives like `cordova-plugin-file-transfer` or `@ionic-native/file` require more boilerplate.

npm install ionic-file-cache
INSTALL
IMPORT
SIG · IONIC-FILE-CACHE
I
ionic-file-cache
storagejavascriptv2.0.48
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.

FileCacheProvider
import { FileCacheProvider } from 'ionic-file-cache'
import FileCacheProvider from 'ionic-file-cache'
Named export, not default. Use curly braces.
File
import { File } from '@ionic-native/file/ngx'
Ionic Native file plugin. Required for FileCacheProvider to work.
FileTransfer
import { FileTransfer } from '@ionic-native/file-transfer/ngx'
Ionic Native file transfer plugin. Required for downloading files.

Configures FileCacheProvider with caching enabled and 1-hour TTL, then caches a file URL and updates a display URL.

import { FileCacheProvider } from 'ionic-file-cache'; import { File } from '@ionic-native/file/ngx'; import { FileTransfer } from '@ionic-native/file-transfer/ngx'; import { Injectable } from '@angular/core'; @Injectable() export class MediaComponent { public imageUrl: string = 'assets/imgs/loading.gif'; constructor(private fileCachePvdr: FileCacheProvider) { this.fileCachePvdr.setEnableCache(true); this.fileCachePvdr.setDefaultTTL(60 * 60 * 1000); } async getCachedFile(url: string) { this.imageUrl = await this.fileCachePvdr.cachedFile(url); } }
Debug
Known issues
gotchaThe package requires @ionic-native/file and @ionic-native/file-transfer as peer dependencies; they must be installed separately.
fix
npm install @ionic-native/file @ionic-native/file-transfer
affects: *
gotchaFileCacheProvider expects Ionic Native plugins to be provided in Angular module providers; forgetting to add them leads to runtime errors.
fix
Add File and FileTransfer to your @NgModule providers array.
affects: *
gotchaTTL is set in milliseconds; common mistake is passing seconds instead.
fix
Use 60 * 60 * 1000 for 1 hour, not 3600.
affects: *
gotchaThe cachedFile() method returns a local file URL (file://), not a Blob or base64; using it in a browser context will fail.
fix
Only use this package in Ionic/Cordova apps on a real device or emulator.
affects: *
gotchaIf cache is disabled (setEnableCache(false)), cachedFile() still returns the original remote URL, not a local file.
fix
Ensure setEnableCache(true) is called before calling cachedFile().
affects: *
Errors
Common errors & fixes
No provider for FileCacheProvider
FileCacheProvider not added to NgModule providers.
fix
Add FileCacheProvider to providers array in app.module.ts or the module where it's used.
File is not defined
@ionic-native/file plugin not installed or not added to providers.
fix
Install @ionic-native/file and add File to NgModule providers.
FileTransfer is not defined
@ionic-native/file-transfer plugin not installed or not added to providers.
fix
Install @ionic-native/file-transfer and add FileTransfer to NgModule providers.
Upgrade
Version history
2.0.48latest on npm
Audit
Dependencies
@ionic-native/filerequiredRequired for file system access in Ionic apps
@ionic-native/file-transferrequiredRequired for downloading files to cache
Agent activity
26 hits · last 30 days
node
24
Amazon
1
Resources
ionic-file-cache — npm install ionic-file-cache · libregistry