Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@file-cache/core

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@file-cache/core

A cache for file metadata or file content.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@file-cache/core

A cache for file metadata or file content.

Installation

npm install @file-cache/core

Usage

import { createCache } from '@file-cache/core';
// use metadata starategy to detect changes
const cache = await createCache({
    keys: [
        () => "test",
        () => "custom"
    ],
    mode: "metadata"
});
const filePath = path.resolve(__dirname, "./fixtures/f1.txt");
const result = await cache.getAndUpdateCache(filePath);
assert.deepStrictEqual(result, {
    changed: true,
    error: undefined
});
// write the updates to cache file
await cache.reconcile();
// re-get the file status
const result2 = await cache.getAndUpdateCache(filePath);
assert.deepStrictEqual(result2, {
    changed: false,
    error: undefined
});

You can disable cache by noCache options.

import { createCache } from '@file-cache/core';
// use metadata starategy to detect changes
const cache = await createCache({
    keys: [
        () => "test",
        () => "custom"
    ],
    mode: "metadata",
    noCache: true,
});
const filePath = path.resolve(__dirname, "./fixtures/f1.txt");
const result = await cache.getAndUpdateCache(filePath);
assert.deepStrictEqual(result, {
    changed: true,
    error: undefined
});
await cache.reconcile();
// always, the result.changed is true
const result2 = await cache.getAndUpdateCache(filePath);
assert.deepStrictEqual(result2, {
    changed: true,
    error: undefined
});

Options

export type CreateCacheOptions = {
    /**
     * - content: Using the hash value of file content
     *   - Slow but accurate
     * - metadata: Using the metadata of file
     *   - Fast but not accurate
     *   - It can not used in CI env
     */
    mode: "content" | "metadata";
    /**
     * The key generators for cache file
     */
    keys: CreateCacheKeyGenerator[];
    /**
     * Custom cache directory.
     * Default: node_modules/.cache/<pkg-name>
     */
    cacheDirectory?: string;
};

Tests

npm test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

Keywords

FAQs

Package last updated on 30 Jul 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc