@destinationstransfers/cache
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

cache codecov node tested with jest license Build Status DeepScan grade

Like cacache, but without localizations and tons of dependencies, while using modern Node features (async/await, fs.promises, stream._final and stream.pipeline) and with full JSDoc for VScode IntelliSense.

Uses subresource integrity control. Disk based, no extra memory caching apart of file system cache.

Usage

const Cache = require('@destinationstransfers/cache');

// to show writable stream example
const assert = require('assert');
const { promisify } = require('util');
const pipeline = promisify(require('stream').pipeline);
const finished = promisify(require('stream').finished);


async fn() {
    const cache = new Cache('someFolderPath');
    const res = await cache.set('key1', buffer);
    /**
     * res => 
     * {
      integrity: string,
      path: string,
      size: number,
      time: Date,
      metadata?: any,
    }
     **/

    const valBuf = await cache.get('key1');
    await cache.delete('key1');

    // The same with Streams
    const res1 = await cache.setStream('key1', someReadable);
    const readable = cache.getStream('key1');
    // or you may get writable stream and push into it
    await pipeline(
        request.get('https:/.....'),
        cache.getWritableStream('cache-url1', { metadata: { url } })
    );
    assert.ok(cache.has('cache-url1').metadata.url, 'Content must be in cache now with associated metadata')
    // or intermittent caching layer
    await finished(
        createReadStream('oldFilename.ext')
            .pipe(cache.createCachingStream('cachingKey'))
            .pipe(createWriteStream('newLocation.ext'))
    )
}

Doesn't store the same content twice.

Readme

Keywords

none

Package Sidebar

Install

npm i @destinationstransfers/cache

Weekly Downloads

2

Version

2.2.1

License

MIT

Unpacked Size

19.4 kB

Total Files

5

Last publish

Collaborators

  • tinovyatkin