Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cachu

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachu

Simple, minimalistic key-value cache.

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

cachu

Simple, minimalistic key-value cache, created by Devyl.

Why use it?

  • fully asynchronous
  • small n' easy
  • zero dependencies

Installation

Install the package using your favorite manager.

npm i cachu
yarn add cachu

Create a basic cache instance.

import cache from 'cachu'

const myCache = new cache({
  max: 10, // cache can contain up to 10 items
  maxAge: 60 // delete each item after 1 minute
})

async function demo() {
  await myCache.setKey('some key', 'hello world')
}

demo()

Configuration

  • maxAge to set the maximum age for each item in the cache
    👉 900 (seconds) by default

  • max to set the maximum size for the store
    👉 Infinity by default

  • maxLength to set the maximum length for each item
    👉 Infinity by default (affects only strings)

Features

  • setKey(key, value) to set a new item (will return either true or false)
    👉 key can be anything, nevertheless it should be unique
    👉 value can be of any type, doesn't have to be unique

  • getKey(key) to get a item
    👉 will return the value of the item or null if it doesn't exist

  • updateKey(key, value) to update a key (will return either true or false)
    👉 key has to exist, in case it doesn't it'll return false
    👉 value can be of any type, doesn't have to be unique

  • stealKey(key) to get a item without modifying anything
    👉 will return the value of the item or null if it doesn't exist

  • hasKey(key) to check if a key exists
    👉 will return either true or false

  • hasValue(value) to check if any item has a specific value
    👉 will return either true or false

  • deleteKey(key) to delete a key
    👉 will return either true or false

  • purge() to reset the cache

FAQs

Package last updated on 02 Oct 2021

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc