@file-cache/core
A cache for file metadata or file content.
Installation
npm install @file-cache/core
Usage
import { createCache } from '@file-cache/core';
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
});
await cache.reconcile();
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';
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();
const result2 = await cache.getAndUpdateCache(filePath);
assert.deepStrictEqual(result2, {
changed: true,
error: undefined
});
Options
export type CreateCacheOptions = {
mode: "content" | "metadata";
keys: CreateCacheKeyGenerator[];
cacheDirectory?: string;
};
Tests
npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT