Socket
Socket
Sign inDemoInstall

@garraflavatra/chowchow

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @garraflavatra/chowchow

Efficient and customisable caching made easy.


Version published
Weekly downloads
0
Maintainers
1
Install size
17.2 kB
Created
Weekly downloads
 

Readme

Source

Chowchow

API docs

Efficient and customisable server-side caching made easy. Chowchow caches everything you want to cache, from CMS data to API responses.

  • 🚀 Makes your app faster.
  • 💼 Bring your own function to get the data.
  • 🕰 Expiration time from 2 seconds to 2 eons.
  • 🪶 Extremely lightweight (1.8 kB).

Installation

npm install @garraflavatra/chowchow

Usage

API docs

import CacheStore from 'chowchow';

const cache = new CacheStore(
	/* Store name */ 'cache',
	/* Callback that fetches data */ async () => {
		const res = await fetch('http://localhost:5000/myapi');
		if (!res.ok) return { success: false };

		const entries = await res.json();
		const filtered = entries.filter(e => e.status === 'online');
		if (!filtered.length) return { success: false };

		return { success: true, data: onlineEntries };
	},
	/* Maximum age in minutes */ 15,
	/* Cache file directory */ '.cache',
	/* File name */ 'cache'
);

Get the data

API docs

If the cache is not expired yet according to the expiration time, it will return the cache. Otherwise it will fetch new data, save it to the store, and return it.

const data = cache.getData();

Read the cache

API docs

This returns the cache, regardless of whether it is expired or not.

const cachedData = cache.readCache();

Get fresh data

API docs

This fetches fresh data and returns it, regardless of whether it is expired or not. The function is the given callback parameter of the constructor. Note that this does not write the cache to the cache file.

const freshData = cache.getFreshData();

License

MIT

Keywords

FAQs

Last updated on 12 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc