tabby-cache

1.0.2 • Public • Published

tabby-cache

The smallest cache library that actually works.
37 lines of code, 0 dependencies

Installation

Current stable version: 1.0

$ npm install tabby-cache

Usage

const TabbyCache = require('tabby-cache');
const cache = new TabbyCache(60); // in seconds

const obj = 'object'; // string, number, boolean, object, array
cache.set(obj, 'cache-key'); // set the cache

// cache that exists
cache.get('cache-key'); // return obj

// cache that doesn't exists
cache.get('cache'); // return undefined

Example:

const TabbyCache = require('tabby-cache');
const cache = new TabbyCache(300);
const fetch = require('node-fetch');

async function TabbyApi() {
    const getCache = cache.get('tabby-api');
    if (getCache == undefined) {
        const { users, servers } = await fetch('https://api.tabbybot.eu/').then(res => res.json());
        cache.set(users, 'tabby-api');
    } else {
        cache.get('tabby-api');
    };
};

Package Sidebar

Install

npm i tabby-cache

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

2.57 kB

Total Files

3

Last publish

Collaborators

  • heges
  • samculo