@file-cache/core

中文文档
2.0.0发布于 2024/01/20MITTypeScriptESM + CJS近 30 天下载 14.5万

文件元数据或文件内容的缓存 .

中文使用文档
文档目录6 节
  1. 安装
  2. 使用量
  3. 选项
  4. 测试
  5. 捐款
  6. 许可证

@ file-cache/ core (帮助)

文件元数据或文件内容的缓存 .

安装

npm install @file-cache/core

使用量

import { createCache } from '@file-cache/core';
// use metadata starategy to detect changes
const cache = await createCache({
    name: "your-tool-name",
    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
});

您可以禁用缓存 noCache 选项.

import { createCache } from '@file-cache/core';
// use metadata starategy to detect changes
const cache = await createCache({
    name: "your-tool-name",
    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
});

选项

export type CreateCacheOptions = {
    /**
     * The name of your tool
     */
    name: string;
    /**
     * - content: Using the hash value of file content
     *   - Slow but accurate
     * - metadata: Using the metadata of file
     *   - Fast but not accurate
     *   - It can not be 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;
};

测试

npm test

捐款

  1. 叉开它!
  2. 创建您的特性分支 : git checkout -b my-new-feature
  3. 提交更改 : git commit -am 'Add some feature'
  4. 推到树枝上: git push origin my-new-feature
  5. 提交拉动请求 : D

许可证

麻省理工学院

版本与发布记录

@file-cache/core 共发布 10 个版本,首次发布于 2022/07/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2024/01/202 年前
1.1.42023/07/173 年前
1.1.32022/08/044 年前
1.1.22022/07/304 年前
1.1.12022/07/304 年前
1.1.02022/07/304 年前

关于 @file-cache/core 的常见问题

@file-cache/core 是什么?

文件元数据或文件内容的缓存 .

如何安装 @file-cache/core?

在项目目录运行 npm install @file-cache/core,或使用 pnpm add / yarn add / bun add。

@file-cache/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@file-cache/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@file-cache/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@file-cache/core 可以商用吗?

@file-cache/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@file-cache/core 的下载量有多少?

根据 npm 官方下载统计,@file-cache/core 在 2026/10/15 – 2026/11/13 这 30 天内被下载 144,704 次,日均约 4,823 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@file-cache/core 还在维护吗?

最新版本 2.0.0 发布于 2024/01/20(2 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。