Skip to content

daverupp/idb-cache

This branch is 2 commits ahead of drecom/idb-cache:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b014d94 · May 3, 2021

History

54 Commits
May 3, 2021
May 30, 2019
May 3, 2021
May 11, 2018
May 3, 2021
May 1, 2018
Apr 19, 2018
May 2, 2018
May 30, 2019
May 3, 2021
Jun 10, 2019
May 30, 2019
May 30, 2019

Repository files navigation

idb-cache

Build Status npm version license

idb-cache is a fast and simple cache library for JavaScript using IndexedDB.

IndexedDB is persistent storage, but idb-cache automatically destroys old files. Therefore, users do not have to worry about storage pressure due to garbage files.

Usage

Initialization

const idbc = new IDBCache('examplesDB', {
  size : 52428800, // Size limit (Default 50MB)
  count : 100, // Number of files limit (Default 100)
  defaultAge : 86400, // max-age when there is no setting (Default 1day)
});

Set cache

// Designate max-age
idbc.set('key1', 'value1'); // defaultAge cache
idbc.set('key2', 'value2', 604800); // 1week cache

// Supported type
idbc.set('key3', new ArrayBuffer(512)); // ArrayBuffer
idbc.set('key4', new Blob([new ArrayBuffer(1024)])); // Blob

Get cache

idbc.get('key1').then(function(value){
  console.log(value);
}).catch(function(){
  // Does not exist, expired or error
});

Target

idb-cache is focused on support of the following browsers.

  • Chrome for Android
  • iOS Safari (Support from v10)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 66.2%
  • JavaScript 33.8%