2.2.1 • Published 5 years ago

@destinationstransfers/cache v2.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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.

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago