\href{https://github.com/npm/cacache}{\texttt{ {\ttfamily cacache}}} is a Node.\+js library for managing local key and content address caches. It\textquotesingle{}s really fast, really good at concurrency, and it will never give you corrupted data, even if cache files get corrupted or manipulated.

On systems that support user and group settings on files, cacache will match the {\ttfamily uid} and {\ttfamily gid} values to the folder where the cache lives, even when running as {\ttfamily root}.

It was written to be used as \href{https://npm.im}{\texttt{ npm}}\textquotesingle{}s local cache, but can just as easily be used on its own.

{\itshape Translations\+: \mbox{\hyperlink{md_sfcode_node_modules_webpack_node_modules_cacache_README_es}{español}}}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32381}{}\doxysection{Install}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32381}
{\ttfamily \$ npm install -\/-\/save cacache}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32382}{}\doxysection{Table of Contents}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32382}

\begin{DoxyItemize}
\item \href{\#example}{\texttt{ Example}}
\item \href{\#features}{\texttt{ Features}}
\item \href{\#contributing}{\texttt{ Contributing}}
\item \href{\#api}{\texttt{ API}}
\begin{DoxyItemize}
\item \href{\#localized-api}{\texttt{ Using localized APIs}}
\item Reading
\begin{DoxyItemize}
\item \href{\#ls}{\texttt{ {\ttfamily ls}}}
\item \href{\#ls-stream}{\texttt{ {\ttfamily ls.\+stream}}}
\item \href{\#get-data}{\texttt{ {\ttfamily get}}}
\item \href{\#get-stream}{\texttt{ {\ttfamily get.\+stream}}}
\item \href{\#get-info}{\texttt{ {\ttfamily get.\+info}}}
\item \href{\#get-hasContent}{\texttt{ {\ttfamily get.\+has\+Content}}}
\end{DoxyItemize}
\item Writing
\begin{DoxyItemize}
\item \href{\#put-data}{\texttt{ {\ttfamily put}}}
\item \href{\#put-stream}{\texttt{ {\ttfamily put.\+stream}}}
\item \href{\#put-options}{\texttt{ {\ttfamily put$\ast$} opts}}
\item \href{\#rm-all}{\texttt{ {\ttfamily rm.\+all}}}
\item \href{\#rm-entry}{\texttt{ {\ttfamily rm.\+entry}}}
\item \href{\#rm-content}{\texttt{ {\ttfamily rm.\+content}}}
\end{DoxyItemize}
\item Utilities
\begin{DoxyItemize}
\item \href{\#set-locale}{\texttt{ {\ttfamily set\+Locale}}}
\item \href{\#clear-memoized}{\texttt{ {\ttfamily clear\+Memoized}}}
\item \href{\#tmp-mkdir}{\texttt{ {\ttfamily tmp.\+mkdir}}}
\item \href{\#with-tmp}{\texttt{ {\ttfamily tmp.\+with\+Tmp}}}
\end{DoxyItemize}
\item Integrity
\begin{DoxyItemize}
\item \href{\#integrity}{\texttt{ Subresource Integrity}}
\item \href{\#verify}{\texttt{ {\ttfamily verify}}}
\item \href{\#verify-last-run}{\texttt{ {\ttfamily verify.\+last\+Run}}}
\end{DoxyItemize}
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32383}{}\doxysubsection{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32383}

\begin{DoxyCode}{0}
\DoxyCodeLine{const cacache = require('cacache/en')}
\DoxyCodeLine{const fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{const tarball = '/path/to/mytar.tgz'}
\DoxyCodeLine{const cachePath = '/tmp/my-\/toy-\/cache'}
\DoxyCodeLine{const key = 'my-\/unique-\/key-\/1234'}
\DoxyCodeLine{}
\DoxyCodeLine{// Cache it! Use `cachePath` as the root of the content cache}
\DoxyCodeLine{cacache.put(cachePath, key, '10293801983029384').then(integrity => \{}
\DoxyCodeLine{  console.log(`Saved content to \$\{cachePath\}.`)}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{const destination = '/tmp/mytar.tgz'}
\DoxyCodeLine{}
\DoxyCodeLine{// Copy the contents out of the cache and into their destination!}
\DoxyCodeLine{// But this time, use stream instead!}
\DoxyCodeLine{cacache.get.stream(}
\DoxyCodeLine{  cachePath, key}
\DoxyCodeLine{).pipe(}
\DoxyCodeLine{  fs.createWriteStream(destination)}
\DoxyCodeLine{).on('finish', () => \{}
\DoxyCodeLine{  console.log('done extracting!')}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// The same thing, but skip the key index.}
\DoxyCodeLine{cacache.get.byDigest(cachePath, integrityHash).then(data => \{}
\DoxyCodeLine{  fs.writeFile(destination, data, err => \{}
\DoxyCodeLine{    console.log('tarball data fetched based on its sha512sum and written out!')}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32384}{}\doxysubsection{Features}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32384}

\begin{DoxyItemize}
\item Extraction by key or by content address (shasum, etc)
\item \href{\#integrity}{\texttt{ Subresource Integrity}} web standard support
\item Multi-\/hash support -\/ safely host sha1, sha512, etc, in a single cache
\item Automatic content deduplication
\item Fault tolerance (immune to corruption, partial writes, process races, etc)
\item Consistency guarantees on read and write (full data verification)
\item Lockless, high-\/concurrency cache access
\item Streaming support
\item Promise support
\item Pretty darn fast -- sub-\/millisecond reads and writes including verification
\item Arbitrary metadata storage
\item Garbage collection and additional offline verification
\item Thorough test coverage
\item There\textquotesingle{}s probably a bloom filter in there somewhere. Those are cool, right? 🤔
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32385}{}\doxysubsection{Contributing}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32385}
The cacache team enthusiastically welcomes contributions and project participation! There\textquotesingle{}s a bunch of things you can do if you want to contribute! The Contributor Guide has all the information you need for everything from reporting bugs to contributing entire new features. Please don\textquotesingle{}t hesitate to jump in if you\textquotesingle{}d like to, or even ask us questions if something isn\textquotesingle{}t clear.

All participants and maintainers in this project are expected to follow Code of Conduct, and just generally be excellent to each other.

Please refer to the \mbox{\hyperlink{md_sfcode_node_modules_webpack_node_modules_cacache_CHANGELOG}{Changelog}} for project history details, too.

Happy hacking!\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32386}{}\doxysubsection{API}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32386}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32387}{}\doxysubsubsection{$<$a name=\char`\"{}localized-\/api\char`\"{}$>$$<$/a$>$ Using localized APIs}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32387}
cacache includes a complete API in English, with the same features as other translations. To use the English API as documented in this README, use `require(\textquotesingle{}cacache/en'){\ttfamily . This is also currently the default if you do }require(\textquotesingle{}cacache\textquotesingle{})\`{}, but may change in the future.

cacache also supports other languages! You can find the list of currently supported ones by looking in {\ttfamily ./locales} in the source directory. You can use the API in that language with `require(\textquotesingle{}cacache/$<$lang$>$')\`{}.

Want to add support for a new language? Please go ahead! You should be able to copy {\ttfamily ./locales/en.js} and {\ttfamily ./locales/en.json} and fill them in. Translating the {\ttfamily README.\+md} is a bit more work, but also appreciated if you get around to it. 👍🏼\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32388}{}\doxysubsubsection{$<$a name=\char`\"{}ls\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+ls(cache) -\/$>$ Promise$<$\+Object$>$$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32388}
Lists info for all entries currently in the cache as a single large object. Each entry in the object will be keyed by the unique index key, with corresponding \href{\#get-info}{\texttt{ {\ttfamily get.\+info}}} objects as the values.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32389}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32389}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.ls(cachePath).then(console.log)}
\DoxyCodeLine{// Output}
\DoxyCodeLine{\{}
\DoxyCodeLine{  'my-\/thing': \{}
\DoxyCodeLine{    key: 'my-\/thing',}
\DoxyCodeLine{    integrity: 'sha512-\/BaSe64/EnCoDED+HAsh=='}
\DoxyCodeLine{    path: '.testcache/content/deadbeef', // joined with `cachePath`}
\DoxyCodeLine{    time: 12345698490,}
\DoxyCodeLine{    size: 4023948,}
\DoxyCodeLine{    metadata: \{}
\DoxyCodeLine{      name: 'blah',}
\DoxyCodeLine{      version: '1.2.3',}
\DoxyCodeLine{      description: 'this was once a package but now it is my-\/thing'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  'other-\/thing': \{}
\DoxyCodeLine{    key: 'other-\/thing',}
\DoxyCodeLine{    integrity: 'sha1-\/ANothER+hasH=',}
\DoxyCodeLine{    path: '.testcache/content/bada55',}
\DoxyCodeLine{    time: 11992309289,}
\DoxyCodeLine{    size: 111112}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32390}{}\doxysubsubsection{$<$a name=\char`\"{}ls-\/stream\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+ls.\+stream(cache) -\/$>$ Readable$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32390}
Lists info for all entries currently in the cache as a single large object.

This works just like \href{\#ls}{\texttt{ {\ttfamily ls}}}, except \href{\#get-info}{\texttt{ {\ttfamily get.\+info}}} entries are returned as `\textquotesingle{}data'\`{} events on the returned stream.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32391}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32391}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.ls.stream(cachePath).on('data', console.log)}
\DoxyCodeLine{// Output}
\DoxyCodeLine{\{}
\DoxyCodeLine{  key: 'my-\/thing',}
\DoxyCodeLine{  integrity: 'sha512-\/BaSe64HaSh',}
\DoxyCodeLine{  path: '.testcache/content/deadbeef', // joined with `cachePath`}
\DoxyCodeLine{  time: 12345698490,}
\DoxyCodeLine{  size: 13423,}
\DoxyCodeLine{  metadata: \{}
\DoxyCodeLine{    name: 'blah',}
\DoxyCodeLine{    version: '1.2.3',}
\DoxyCodeLine{    description: 'this was once a package but now it is my-\/thing'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\{}
\DoxyCodeLine{  key: 'other-\/thing',}
\DoxyCodeLine{  integrity: 'whirlpool-\/WoWSoMuchSupport',}
\DoxyCodeLine{  path: '.testcache/content/bada55',}
\DoxyCodeLine{  time: 11992309289,}
\DoxyCodeLine{  size: 498023984029}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\{}
\DoxyCodeLine{  ...}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32392}{}\doxysubsubsection{$<$a name=\char`\"{}get-\/data\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+get(cache, key, \mbox{[}opts\mbox{]}) -\/$>$ Promise(\{data, metadata, integrity\})$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32392}
Returns an object with the cached data, digest, and metadata identified by {\ttfamily key}. The {\ttfamily data} property of this object will be a {\ttfamily Buffer} instance that presumably holds some data that means something to you. I\textquotesingle{}m sure you know what to do with it! cacache just won\textquotesingle{}t care.

{\ttfamily integrity} is a \href{\#integrity}{\texttt{ Subresource Integrity}} string. That is, a string that can be used to verify {\ttfamily data}, which looks like {\ttfamily $<$hash-\/algorithm$>$-\/$<$base64-\/integrity-\/hash$>$}.

If there is no content identified by {\ttfamily key}, or if the locally-\/stored data does not pass the validity checksum, the promise will be rejected.

A sub-\/function, {\ttfamily get.\+by\+Digest} may be used for identical behavior, except lookup will happen by integrity hash, bypassing the index entirely. This version of the function {\itshape only} returns {\ttfamily data} itself, without any wrapper.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32393}{}\doxyparagraph{Note}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32393}
This function loads the entire cache entry into memory before returning it. If you\textquotesingle{}re dealing with Very Large data, consider using \href{\#get-stream}{\texttt{ {\ttfamily get.\+stream}}} instead.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32394}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32394}

\begin{DoxyCode}{0}
\DoxyCodeLine{// Look up by key}
\DoxyCodeLine{cache.get(cachePath, 'my-\/thing').then(console.log)}
\DoxyCodeLine{// Output:}
\DoxyCodeLine{\{}
\DoxyCodeLine{  metadata: \{}
\DoxyCodeLine{    thingName: 'my'}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  integrity: 'sha512-\/BaSe64HaSh',}
\DoxyCodeLine{  data: Buffer\#<deadbeef>,}
\DoxyCodeLine{  size: 9320}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{// Look up by digest}
\DoxyCodeLine{cache.get.byDigest(cachePath, 'sha512-\/BaSe64HaSh').then(console.log)}
\DoxyCodeLine{// Output:}
\DoxyCodeLine{Buffer\#<deadbeef> }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32395}{}\doxysubsubsection{$<$a name=\char`\"{}get-\/stream\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+get.\+stream(cache, key, \mbox{[}opts\mbox{]}) -\/$>$ Readable$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32395}
Returns a \href{https://nodejs.org/api/stream.html\#stream_readable_streams}{\texttt{ Readable Stream}} of the cached data identified by {\ttfamily key}.

If there is no content identified by {\ttfamily key}, or if the locally-\/stored data does not pass the validity checksum, an error will be emitted.

{\ttfamily metadata} and {\ttfamily integrity} events will be emitted before the stream closes, if you need to collect that extra data about the cached entry.

A sub-\/function, {\ttfamily get.\+stream.\+by\+Digest} may be used for identical behavior, except lookup will happen by integrity hash, bypassing the index entirely. This version does not emit the {\ttfamily metadata} and {\ttfamily integrity} events at all.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32396}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32396}

\begin{DoxyCode}{0}
\DoxyCodeLine{// Look up by key}
\DoxyCodeLine{cache.get.stream(}
\DoxyCodeLine{  cachePath, 'my-\/thing'}
\DoxyCodeLine{).on('metadata', metadata => \{}
\DoxyCodeLine{  console.log('metadata:', metadata)}
\DoxyCodeLine{\}).on('integrity', integrity => \{}
\DoxyCodeLine{  console.log('integrity:', integrity)}
\DoxyCodeLine{\}).pipe(}
\DoxyCodeLine{  fs.createWriteStream('./x.tgz')}
\DoxyCodeLine{)}
\DoxyCodeLine{// Outputs:}
\DoxyCodeLine{metadata: \{ ... \}}
\DoxyCodeLine{integrity: 'sha512-\/SoMeDIGest+64=='}
\DoxyCodeLine{}
\DoxyCodeLine{// Look up by digest}
\DoxyCodeLine{cache.get.stream.byDigest(}
\DoxyCodeLine{  cachePath, 'sha512-\/SoMeDIGest+64=='}
\DoxyCodeLine{).pipe(}
\DoxyCodeLine{  fs.createWriteStream('./x.tgz')}
\DoxyCodeLine{) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32397}{}\doxysubsubsection{$<$a name=\char`\"{}get-\/info\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+get.\+info(cache, key) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32397}
Looks up {\ttfamily key} in the cache index, returning information about the entry if one exists.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32398}{}\doxyparagraph{Fields}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32398}

\begin{DoxyItemize}
\item {\ttfamily key} -\/ Key the entry was looked up under. Matches the {\ttfamily key} argument.
\item {\ttfamily integrity} -\/ \href{\#integrity}{\texttt{ Subresource Integrity hash}} for the content this entry refers to.
\item {\ttfamily path} -\/ Filesystem path where content is stored, joined with {\ttfamily cache} argument.
\item {\ttfamily time} -\/ Timestamp the entry was first added on.
\item {\ttfamily metadata} -\/ User-\/assigned metadata associated with the entry/content.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32399}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32399}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.get.info(cachePath, 'my-\/thing').then(console.log)}
\DoxyCodeLine{}
\DoxyCodeLine{// Output}
\DoxyCodeLine{\{}
\DoxyCodeLine{  key: 'my-\/thing',}
\DoxyCodeLine{  integrity: 'sha256-\/MUSTVERIFY+ALL/THINGS=='}
\DoxyCodeLine{  path: '.testcache/content/deadbeef',}
\DoxyCodeLine{  time: 12345698490,}
\DoxyCodeLine{  size: 849234,}
\DoxyCodeLine{  metadata: \{}
\DoxyCodeLine{    name: 'blah',}
\DoxyCodeLine{    version: '1.2.3',}
\DoxyCodeLine{    description: 'this was once a package but now it is my-\/thing'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32400}{}\doxysubsubsection{$<$a name=\char`\"{}get-\/has\+Content\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+get.\+has\+Content(cache, integrity) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32400}
Looks up a \href{\#integrity}{\texttt{ Subresource Integrity hash}} in the cache. If content exists for this {\ttfamily integrity}, it will return an object, with the specific single integrity hash that was found in {\ttfamily sri} key, and the size of the found content as {\ttfamily size}. If no content exists for this integrity, it will return {\ttfamily false}.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32401}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32401}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.get.hasContent(cachePath, 'sha256-\/MUSTVERIFY+ALL/THINGS==').then(console.log)}
\DoxyCodeLine{}
\DoxyCodeLine{// Output}
\DoxyCodeLine{\{}
\DoxyCodeLine{  sri: \{}
\DoxyCodeLine{    source: 'sha256-\/MUSTVERIFY+ALL/THINGS==',}
\DoxyCodeLine{    algorithm: 'sha256',}
\DoxyCodeLine{    digest: 'MUSTVERIFY+ALL/THINGS==',}
\DoxyCodeLine{    options: []}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  size: 9001}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{cacache.get.hasContent(cachePath, 'sha521-\/NOT+IN/CACHE==').then(console.log)}
\DoxyCodeLine{}
\DoxyCodeLine{// Output}
\DoxyCodeLine{false }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32402}{}\doxysubsubsection{$<$a name=\char`\"{}put-\/data\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+put(cache, key, data, \mbox{[}opts\mbox{]}) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32402}
Inserts data passed to it into the cache. The returned Promise resolves with a digest (generated according to \href{\#optsalgorithms}{\texttt{ {\ttfamily opts.\+algorithms}}}) after the cache entry has been successfully written.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32403}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32403}

\begin{DoxyCode}{0}
\DoxyCodeLine{fetch(}
\DoxyCodeLine{  'https://registry.npmjs.org/cacache/-\//cacache-\/1.0.0.tgz'}
\DoxyCodeLine{).then(data => \{}
\DoxyCodeLine{  return cacache.put(cachePath, 'registry.npmjs.org|cacache@1.0.0', data)}
\DoxyCodeLine{\}).then(integrity => \{}
\DoxyCodeLine{  console.log('integrity hash is', integrity)}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32404}{}\doxysubsubsection{$<$a name=\char`\"{}put-\/stream\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+put.\+stream(cache, key, \mbox{[}opts\mbox{]}) -\/$>$ Writable$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32404}
Returns a \href{https://nodejs.org/api/stream.html\#stream_writable_streams}{\texttt{ Writable Stream}} that inserts data written to it into the cache. Emits an {\ttfamily integrity} event with the digest of written contents when it succeeds.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32405}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32405}

\begin{DoxyCode}{0}
\DoxyCodeLine{request.get(}
\DoxyCodeLine{  'https://registry.npmjs.org/cacache/-\//cacache-\/1.0.0.tgz'}
\DoxyCodeLine{).pipe(}
\DoxyCodeLine{  cacache.put.stream(}
\DoxyCodeLine{    cachePath, 'registry.npmjs.org|cacache@1.0.0'}
\DoxyCodeLine{  ).on('integrity', d => console.log(`integrity digest is \$\{d\}`))}
\DoxyCodeLine{) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32406}{}\doxysubsubsection{$<$a name=\char`\"{}put-\/options\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+put options$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32406}
{\ttfamily cacache.\+put} functions have a number of options in common.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32407}{}\doxyparagraph{$<$tt$>$opts.\+metadata$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32407}
Arbitrary metadata to be attached to the inserted key.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32408}{}\doxyparagraph{$<$tt$>$opts.\+size$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32408}
If provided, the data stream will be verified to check that enough data was passed through. If there\textquotesingle{}s more or less data than expected, insertion will fail with an {\ttfamily EBADSIZE} error.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32409}{}\doxyparagraph{$<$tt$>$opts.\+integrity$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32409}
If present, the pre-\/calculated digest for the inserted content. If this option if provided and does not match the post-\/insertion digest, insertion will fail with an {\ttfamily EINTEGRITY} error.

{\ttfamily algorithms} has no effect if this option is present.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32410}{}\doxyparagraph{$<$tt$>$opts.\+algorithms$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32410}
Default\+: \mbox{[}\textquotesingle{}sha512\textquotesingle{}\mbox{]}

Hashing algorithms to use when calculating the \href{\#integrity}{\texttt{ subresource integrity digest}} for inserted data. Can use any algorithm listed in {\ttfamily crypto.\+get\+Hashes()} or `\textquotesingle{}omakase'{\ttfamily /}\textquotesingle{}お任せします\textquotesingle{}{\ttfamily to pick a random hash algorithm on each insertion. You may also use any anagram of}\textquotesingle{}modnar\textquotesingle{}\`{} to use this feature.

Currently only supports one algorithm at a time (i.\+e., an array length of exactly {\ttfamily 1}). Has no effect if {\ttfamily opts.\+integrity} is present.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32411}{}\doxyparagraph{$<$tt$>$opts.\+memoize$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32411}
Default\+: null

If provided, cacache will memoize the given cache insertion in memory, bypassing any filesystem checks for that key or digest in future cache fetches. Nothing will be written to the in-\/memory cache unless this option is explicitly truthy.

If {\ttfamily opts.\+memoize} is an object or a {\ttfamily Map}-\/like (that is, an object with {\ttfamily get} and {\ttfamily set} methods), it will be written to instead of the global memoization cache.

Reading from disk data can be forced by explicitly passing {\ttfamily memoize\+: false} to the reader functions, but their default will be to read from memory.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32412}{}\doxysubsubsection{$<$a name=\char`\"{}rm-\/all\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+rm.\+all(cache) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32412}
Clears the entire cache. Mainly by blowing away the cache directory itself.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32413}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32413}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.rm.all(cachePath).then(() => \{}
\DoxyCodeLine{  console.log('THE APOCALYPSE IS UPON US 😱')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32414}{}\doxysubsubsection{$<$a name=\char`\"{}rm-\/entry\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+rm.\+entry(cache, key) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32414}
Alias\+: {\ttfamily cacache.\+rm}

Removes the index entry for {\ttfamily key}. Content will still be accessible if requested directly by content address (\href{\#get-stream}{\texttt{ {\ttfamily get.\+stream.\+by\+Digest}}}).

To remove the content itself (which might still be used by other entries), use \href{\#rm-content}{\texttt{ {\ttfamily rm.\+content}}}. Or, to safely vacuum any unused content, use \href{\#verify}{\texttt{ {\ttfamily verify}}}.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32415}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32415}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.rm.entry(cachePath, 'my-\/thing').then(() => \{}
\DoxyCodeLine{  console.log('I did not like it anyway')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32416}{}\doxysubsubsection{$<$a name=\char`\"{}rm-\/content\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+rm.\+content(cache, integrity) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32416}
Removes the content identified by {\ttfamily integrity}. Any index entries referring to it will not be usable again until the content is re-\/added to the cache with an identical digest.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32417}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32417}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.rm.content(cachePath, 'sha512-\/SoMeDIGest/IN+BaSE64==').then(() => \{}
\DoxyCodeLine{  console.log('data for my-\/thing is gone!')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32418}{}\doxysubsubsection{$<$a name=\char`\"{}set-\/locale\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+set\+Locale(locale)$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32418}
Configure the language/locale used for messages and errors coming from cacache. The list of available locales is in the {\ttfamily ./locales} directory in the project root.

{\itshape Interested in contributing more languages! Submit a PR!}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32419}{}\doxysubsubsection{$<$a name=\char`\"{}clear-\/memoized\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+clear\+Memoized()$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32419}
Completely resets the in-\/memory entry cache.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32420}{}\doxysubsubsection{$<$a name=\char`\"{}tmp-\/mkdir\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ tmp.\+mkdir(cache, opts) -\/$>$ Promise$<$\+Path$>$$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32420}
Returns a unique temporary directory inside the cache\textquotesingle{}s {\ttfamily tmp} dir. This directory will use the same safe user assignment that all the other stuff use.

Once the directory is made, it\textquotesingle{}s the user\textquotesingle{}s responsibility that all files within are given the appropriate {\ttfamily gid}/{\ttfamily uid} ownership settings to match the rest of the cache. If not, you can ask cacache to do it for you by calling \href{\#tmp-fix}{\texttt{ {\ttfamily tmp.\+fix()}}}, which will fix all tmp directory permissions.

If you want automatic cleanup of this directory, use \href{\#with-tpm}{\texttt{ {\ttfamily tmp.\+with\+Tmp()}}}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32421}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32421}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.tmp.mkdir(cache).then(dir => \{}
\DoxyCodeLine{  fs.writeFile(path.join(dir, 'blablabla'), Buffer\#<1234>, ...)}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32422}{}\doxysubsubsection{$<$a name=\char`\"{}tmp-\/fix\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ tmp.\+fix(cache) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32422}
Sets the {\ttfamily uid} and {\ttfamily gid} properties on all files and folders within the tmp folder to match the rest of the cache.

Use this after manually writing files into \href{\#tmp-mkdir}{\texttt{ {\ttfamily tmp.\+mkdir}}} or \href{\#with-tmp}{\texttt{ {\ttfamily tmp.\+with\+Tmp}}}.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32423}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32423}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.tmp.mkdir(cache).then(dir => \{}
\DoxyCodeLine{  writeFile(path.join(dir, 'file'), someData).then(() => \{}
\DoxyCodeLine{    // make sure we didn't just put a root-\/owned file in the cache}
\DoxyCodeLine{    cacache.tmp.fix().then(() => \{}
\DoxyCodeLine{      // all uids and gids match now}
\DoxyCodeLine{    \})}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32424}{}\doxysubsubsection{$<$a name=\char`\"{}with-\/tmp\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ tmp.\+with\+Tmp(cache, opts, cb) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32424}
Creates a temporary directory with \href{\#tmp-mkdir}{\texttt{ {\ttfamily tmp.\+mkdir()}}} and calls {\ttfamily cb} with it. The created temporary directory will be removed when the return value of {\ttfamily cb()} resolves -- that is, if you return a Promise from {\ttfamily cb()}, the tmp directory will be automatically deleted once that promise completes.

The same caveats apply when it comes to managing permissions for the tmp dir\textquotesingle{}s contents.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32425}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32425}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.tmp.withTmp(cache, dir => \{}
\DoxyCodeLine{  return fs.writeFileAsync(path.join(dir, 'blablabla'), Buffer\#<1234>, ...)}
\DoxyCodeLine{\}).then(() => \{}
\DoxyCodeLine{  // `dir` no longer exists}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32426}{}\doxysubsubsection{$<$a name=\char`\"{}integrity\char`\"{}$>$$<$/a$>$ Subresource Integrity Digests}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32426}
For content verification and addressing, cacache uses strings following the \href{https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity}{\texttt{ Subresource Integrity spec}}. That is, any time cacache expects an {\ttfamily integrity} argument or option, it should be in the format {\ttfamily $<$hash\+Algorithm$>$-\/$<$base64-\/hash$>$}.

One deviation from the current spec is that cacache will support any hash algorithms supported by the underlying Node.\+js process. You can use {\ttfamily crypto.\+get\+Hashes()} to see which ones you can use.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32427}{}\doxyparagraph{Generating Digests Yourself}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32427}
If you have an existing content shasum, they are generally formatted as a hexadecimal string (that is, a sha1 would look like\+: {\ttfamily 5f5513f8822fdbe5145af33b64d8d970dcf95c6e}). In order to be compatible with cacache, you\textquotesingle{}ll need to convert this to an equivalent subresource integrity string. For this example, the corresponding hash would be\+: {\ttfamily sha1-\/\+X1\+UT+\+IIv2+\+UUWv\+M7\+ZNj\+Zc\+Nz5\+XG4=}.

If you want to generate an integrity string yourself for existing data, you can use something like this\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const crypto = require('crypto')}
\DoxyCodeLine{const hashAlgorithm = 'sha512'}
\DoxyCodeLine{const data = 'foobarbaz'}
\DoxyCodeLine{}
\DoxyCodeLine{const integrity = (}
\DoxyCodeLine{  hashAlgorithm +}
\DoxyCodeLine{  '-\/' +}
\DoxyCodeLine{  crypto.createHash(hashAlgorithm).update(data).digest('base64')}
\DoxyCodeLine{) }

\end{DoxyCode}


You can also use \href{https://npm.im/ssri}{\texttt{ {\ttfamily ssri}}} to have a richer set of functionality around SRI strings, including generation, parsing, and translating from existing hex-\/formatted strings.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32428}{}\doxysubsubsection{$<$a name=\char`\"{}verify\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+verify(cache, opts) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32428}
Checks out and fixes up your cache\+:


\begin{DoxyItemize}
\item Cleans up corrupted or invalid index entries.
\item Custom entry filtering options.
\item Garbage collects any content entries not referenced by the index.
\item Checks integrity for all content entries and removes invalid content.
\item Fixes cache ownership.
\item Removes the {\ttfamily tmp} directory in the cache and all its contents.
\end{DoxyItemize}

When it\textquotesingle{}s done, it\textquotesingle{}ll return an object with various stats about the verification process, including amount of storage reclaimed, number of valid entries, number of entries removed, etc.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32429}{}\doxyparagraph{Options}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32429}

\begin{DoxyItemize}
\item {\ttfamily opts.\+filter} -\/ receives a formatted entry. Return false to remove it. Note\+: might be called more than once on the same entry.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32430}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32430}

\begin{DoxyCode}{0}
\DoxyCodeLine{echo somegarbage >> \$CACHEPATH/content/deadbeef }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.verify(cachePath).then(stats => \{}
\DoxyCodeLine{  // deadbeef collected, because of invalid checksum.}
\DoxyCodeLine{  console.log('cache is much nicer now! stats:', stats)}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32431}{}\doxysubsubsection{$<$a name=\char`\"{}verify-\/last-\/run\char`\"{}$>$$<$/a$>$ $<$tt$>$$>$ cacache.\+verify.\+last\+Run(cache) -\/$>$ Promise$<$/tt$>$}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32431}
Returns a {\ttfamily Date} representing the last time {\ttfamily cacache.\+verify} was run on {\ttfamily cache}.\hypertarget{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32432}{}\doxyparagraph{Example}\label{md_sfcode_node_modules_webpack_node_modules_cacache_README_autotoc_md32432}

\begin{DoxyCode}{0}
\DoxyCodeLine{cacache.verify(cachePath).then(() => \{}
\DoxyCodeLine{  cacache.verify.lastRun(cachePath).then(lastTime => \{}
\DoxyCodeLine{    console.log('cacache.verify was last called on' + lastTime)}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}) }

\end{DoxyCode}
 