Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

offline-first-storage

0.0.5 • Public • Published

Offline first storage

Offline first logic for yor application

NPM

npm version Build Status Coverage Status Linux Build Windows Build

Dependency Status devDependency Status NSP Status

License GitHub stars GitHub forks GitHub issues Twitter

How to install

npm i -S offline-first-storage

How to use

const OFS = require('offline-first-storage');

const cache = new OFS({
    async getDataFromSource() {},
    async getDataFromCache() {},
    async setDataToCache(data) {},
    async getCacheDate() {},
    async updateCacheDate() {},
    timeoutErrorHandler(error) {},
    ttl: 86400, // 24 hours
});

const data = await cache.getData();

ioredis example

const Redis = require('ioredis');
const redis = new Redis();

const key = 'test';

const cache = new Ofs({
    async getDataFromSource() {
        return test;
    },
    async getDataFromCache() {
        return redis.get(key);
    },
    async setDataToCache(data) {
        await redis.set(key, data);
    },
    async getCacheDate() {
        return redis.get(`date_${key}`);
    },
    async updateCacheDate() {
        await redis.set(`date_${key}`, new Date().valueOf());
    },
    timeoutErrorHandler(error) {
        debug(error);
    },
    ttl: 86400,
});

const data = await cache.getData();

Links

  • ioredis - promise based node.js redis client
  • config - node.js config
  • debug - node.js debugging utility

install

npm i offline-first-storage

Downloadsweekly downloads

16

version

0.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability