Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

cacache 18.0.2

Fast, fault-tolerant, cross-platform, disk-based, data-agnostic, content-addressable cache.
Package summary
Share
0
issues
0
licenses
Package created
18 Nov 2016
Version published
4 Jan 2024
Maintainers
5
Total deps
0
Direct deps
0
License
ISC
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does cacache do?

Cacache is a powerful JavaScript library that manages local key and content address caches. It is known for its speed, excellent concurrency handling, and fault tolerance that ensures data integrity even if cache files get corrupted or manipulated. Cacache maintains consistent read and write operations, provides automatic content deduplication, and supports multi-hash storage, enabling appropriate management of sha1, sha512, etc., in a single cache. It is designed with a streaming support feature for efficient data handling and also provides utility functions for managing cache directories along with offline verification and garbage collection for maintaining cache efficiency. Cacache was originally developed as npm's local cache but its functionality makes it easy to use as an independent caching solution.

How do you use cacache?

To use Cacache, you first need to install it using npm by running $ npm install --save cacache. After installing, you can require it in your program and use it to read or write cache data. Here are a few examples:

To write data to a cache, you can use cacache's put method as follows:

const cacache = require('cacache')
const cachePath = '/tmp/my-toy-cache'
const key = 'my-unique-key-1234'

cacache.put(cachePath, key, '10293801983029384').then(integrity => {
  console.log(`Saved content to ${cachePath}.`)
})

In this example '10293801983029384' is the content being saved in the cache, under the 'cachePath' directory with 'my-unique-key-1234' as the key.

To read data from a cache, cacache provides get and get.stream methods:

const fs = require('fs')

const destination = '/tmp/mytar.tgz'

// Read the contents out of the cache and into their destination
cacache.get.stream(
  cachePath, key
).pipe(
  fs.createWriteStream(destination)
).on('finish', () => {
  console.log('done extracting!')
})

const integrityHash = 'sha512-BaSe64/EnCoDED+HAsh=='

// The same thing, but skip the key index.
cacache.get.byDigest(cachePath, integrityHash).then(data => {
  fs.writeFile(destination, data, err => {
    console.log('tarball data fetched based on its sha512sum and written out!')
  })
})

In these examples, data corresponding to a certain key or a content integrity hash is being extracted from the cache and written to a file.

Where are the cacache docs?

The primary source of information on how to use cacache is the documentation provided in the Readme file on its GitHub page: git+https://github.com/npm/cacache.git. You can find detailed instructions on how to install and use the library, code examples, a comprehensive list of API endpoints and methods, descriptions of important features, and insights into how cacache manages the cache. The Readme also includes guidance on how to contribute to the project and its code of conduct.