🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

async-disk-cache

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
a

async-disk-cache

Async disk cache

2.1.0
latest
99

Supply Chain Security

100

Vulnerability

94

Quality

80

Maintenance

100

License

Version published
Weekly downloads
384K
-24.83%
Maintainers
3
Weekly downloads
 
Created
Issues
8

What is async-disk-cache?

The async-disk-cache npm package is a simple and efficient way to cache data on disk asynchronously. It is useful for scenarios where you need to store and retrieve data quickly without relying on in-memory storage, which can be volatile and limited in size.

What are async-disk-cache's main functionalities?

Set Cache

This feature allows you to set a cache entry with a specific key and value. The data is stored on disk asynchronously.

const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');

async function setCache(key, value) {
  await cache.set(key, value);
  console.log(`Cache set for key: ${key}`);
}

setCache('exampleKey', 'exampleValue');

Get Cache

This feature allows you to retrieve a cache entry by its key. It checks if the data is cached and returns the value if it exists.

const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');

async function getCache(key) {
  const result = await cache.get(key);
  if (result.isCached) {
    console.log(`Cache hit for key: ${key}, value: ${result.value}`);
  } else {
    console.log(`Cache miss for key: ${key}`);
  }
}

getCache('exampleKey');

Remove Cache

This feature allows you to remove a cache entry by its key. The data is deleted from the disk asynchronously.

const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');

async function removeCache(key) {
  await cache.remove(key);
  console.log(`Cache removed for key: ${key}`);
}

removeCache('exampleKey');

Clear Cache

This feature allows you to clear all cache entries. It removes all data stored in the cache asynchronously.

const Cache = require('async-disk-cache');
const cache = new Cache('my-cache');

async function clearCache() {
  await cache.clear();
  console.log('All cache cleared');
}

clearCache();

Other packages similar to async-disk-cache

FAQs

Package last updated on 24 Jun 2020

Did you know?

Socket

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