Socket
Socket
Sign inDemoInstall

cachu

Package Overview
Dependencies
1
Maintainers
2
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cachu

👾 A simple key-value cache for Node.js.


Version published
Weekly downloads
4
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

v7.0.0

Breaking Changes

  • changed the way you create a new cache.

    // before v7
    import { useCache } from 'cachu'
    
    const cache = useCache({
      maxAge: '10m',
      maxAmount: 10000,
      autodelete: false
    })
    
    // v7
    import { Cache } from 'cachu'
    
    const cache = new Cache({
      maximumAge: '10m',
      maximumAmount: 10000,
      autodelete: false
    })
    

New Features

  • you can now set a maximum size for each record.

    import { Cache } from 'cachu'
    
    const cache = new Cache({
      maximumRecordSize: '10 KB'
    
      // alternatively, you can specify the amount of bytes as a number
      maximumRecordSize: 10000
    })
    

Readme

Source

cachu

Setup

# Get the latest release.
npm i cachu

Usage

import { Cache } from 'cachu'

const cache = new Cache({
  maximumAge: '10m', // 10 minutes, can be specified as number (in seconds) or readable string
  ...
})

// Add a new record.
await cache.add('one', 'Hello World')
  
const record = await cache.get('one') // 'Hello World'

API

  • Configuration (optional)
    • autodelete to delete overaged entries on adding/updating (disabled by default)
    • maximumAge to set the maximum age for each record in the cache (defaults to 600s)
    • maximumAmount to set the maximum size for the cache (defaults to 10000)
    • maximumRecordSize to set the maximum size for each record (defaults to 10 KB)
  • Features
    • add()
    • addMany()
    • get()
    • getMany()
    • update()
    • updateMany()
    • remove()
    • removeMany()
    • has()
    • size() (get the cache size in bytes)
    • keys()
    • values()
    • clear() (delete all overaged records manually)

FAQs

Last updated on 29 Oct 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