Node.js library that provide a cache for file metadata or file content.

Overview

@file-cache

A cache library for file metadata or file content.

It is useful for process that work a given series of files and that only need to repeat the job on the changed ones since the previous run of the process.

When to update the cache

  • When the source code changes.
  • When the source code metadata changes.
  • When the dependencies change.
  • When the configuration changes.

@file-cache package help you to implement --cache for your tools.

Installation

npm install @file-cache/core @file-cache/npm

Usage

Do heavy tasks for only changed files.

import { createCache } from "@file-cache/core";
import { createNpmPackageKey } from "@file-cache/npm"

const prettierConfig = {/* ... */ };
const cache = awaitcreateCache({
    // Use hash value of the content for detecting changes 
    mode: "content", // or "metadata"
    // create key for cache
    keys: [
        // use dependency(version) as cache key
        () => createNpmPackageKey(["prettier"]),
        // use custom key
        () => {
            return JSON.stringify(prettierConfig);
        }
    ],
    noCache: process.env.NO_CACHE_YOUR_TOOL === "true" // disable cache by the flag
});

const targetFiles = ["a.js", "b.js", "c.js"];
const doHeavyTask = (filePath) => {
    // do heavy task
}
for (const targetFile of targetFiles) {
    const result = await cache.getAndUpdateCache(targetFile);
    if (result.error) {
        throw result.error
    }
    if (!result.changed) {
        continue; // no need to update
    }
    doHeavyTask(targetFile);
}
// write cache state to file for persistence
await cache.reconcile();

Examples:

Options:

See package/core documentation.

Cache Mechanism

Cache file directory:

đź“ť You can change the directory by cacheDirectory option.

|- node_modules
  |- .cache
    |- <pkg-name>
      |- <hash-of-cache-key>-<mode>

Cache file structure:

{
"file-path": <result>
}

This library does not clean up previous cache files. When the <hash-of-cache-key> is changed, the previous cache file will not be deleted automatically.

Users

Release flow

npm run versionup:* && npm run release && git add . && git commit -m "update lock" && git push --tags

Related

License

MIT

You might also like...

Dual ownership for NFTs, preventing rugs when collection metadata/royalties are changed

Multisig Ownable Opensea only allows EOAs to make changes to collections, which makes it impossible to use multisigs to secure NFT contracts since whe

Nov 24, 2022

A collection of crypto tokens (metadata, logos, links)

@deliquid/token-list (beta) A multi-chain collection of crypto tokens, including metadata, logos, and more. Installation npm i @deliquid/token-list Ba

Jun 3, 2022

Fetch publication metadata from the INSPIRE-HEP database

Zotero INSPIRE Metadata Updater This is an add-on for the excellent open-source reference manager Zotero. It is useful as most papers from arXiv will

Nov 27, 2022

Passport NFT using on-chain metadata

Passport NFT Collection Setup yarn Environment File (.env) RINKEBY_URL: Ethereum (Rinkeby) Testnet Provider endpoint MATIC_URL: Polygon (Matic Mumbai)

Jun 2, 2022

An Obsidian plugin to upload your notes' metadata to your database.

An Obsidian plugin to upload your notes' metadata to your database.

Obsidian + PostgreSQL = ❤️ An Obsidian plugin to upload your notes' metadata to your database. Features send the Dataview annotations of a page to a P

Dec 19, 2022

A plugin for Obsidian that can create input fields inside your notes and bind them to metadata fields.

Obsidian Meta Bind Plugin This plugin can create input fields inside your notes and bind them to metadata fields. New docs I am currently working on n

Jan 4, 2023

A GitHub Action to enable Pages and extract various metadata about a site

A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as starter workflows.

Jan 1, 2023

For data quality enthousiasts (and dataview lovers): manage the metadata of your notes.

Metadata Menu This plugin is made for data quality enthousiasts: access and manage the metadata of your notes in Obsidian. Metadata Menu adds context

Dec 23, 2022

🎨 Dynamic Token Images and Metadata

ERC721K - Dynamic Token Images and Metadata Overview ERC721K is an ERC721 implementation with zero dependencies for off-chain data. Both the token ima

Dec 29, 2022
Comments
  • fix: update packemon

    fix: update packemon

    We want to treat package as mjs package(type: module).

    I've tested index-wrapper.mjs, but it force type: "commonjs". So, we apply dual packages.

    fix #1 refs https://github.com/milesj/packemon/issues/133#issuecomment-1197451054

    opened by azu 2
Releases(v1.1.3)
  • v1.1.3(Aug 4, 2022)

    What's Changed

    • fix: update moon and packemon by @azu in https://github.com/azu/file-cache/pull/6

    Full Changelog: https://github.com/azu/file-cache/compare/v1.1.2...v1.1.3

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 30, 2022)

    What's Changed

    • feat: add noCache option by @azu in https://github.com/azu/file-cache/pull/4

    Full Changelog: https://github.com/azu/file-cache/compare/v1.0.1...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Jul 30, 2022)

    What's Changed

    • fix: update packemon by @azu in https://github.com/azu/file-cache/pull/2

    New Contributors

    • @azu made their first contribution in https://github.com/azu/file-cache/pull/2

    Full Changelog: https://github.com/azu/file-cache/compare/v1.0.0...v1.0.1

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jul 15, 2022)

Owner
azu
Creator of @textlint, @secretlint, @honkit and @almin. Editor of @efcl, @jser and @ecmascript-daily. Author of @js-primer. (Don't send me email-ad.)
azu
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Yet another library for generating NFT artwork, uploading NFT assets and metadata to IPFS, deploying NFT smart contracts, and minting NFT collections

eznft Yet another library for generating NFT artwork, uploading NFT assets and metadata to IPFS, deploying NFT smart contracts, and minting NFT collec

null 3 Sep 21, 2022
A file sharing service, where you can upload files and provide a download link for anyone on the internet by sharing the link 🔗 or via mail ✉️ which remains active for 24hours 🕙.

eShare | File Sharing App A file sharing service, where you can upload files and provide a download link for anyone on the internet by sharing the lin

Akhil Bhalerao 7 Nov 20, 2022
A cache for @azure/msal-node that uses Azure KeyVault as a store

@intility/msal-keyvault-cache A cache for @azure/msal-node that uses Azure KeyVault as a store. Usage Install with npm install @intility/msal-keyvault

Intility 10 Mar 17, 2022
A modern SQLite store for node-cache-manager

SQLite store for node cache manager A modern SQlite cache store for node-cache-manager. Featuring: Async SQLite3 using sqlite3 async/await support wit

Zohaib Sibte Hassan 40 Oct 31, 2022
A MITM cache between RPCs and a a dAPP. Useful to allow for better performance on a public RPC node

better-cosmos-rpcs A cheaper way to allow for public RPCs as a service WITHOUT scaling issues. No need to rate limit either. How it is done: User GET

Reece Williams 3 Nov 19, 2022
A util for getting data and metadata for all markdown files in a given dir. Useful for building static site generators

extract-md-data A util for getting data and metadata for all markdown files in a given dir. Useful for building static site generators. Usage Given th

Claire Froelich 2 Jan 6, 2022
The ICPverse service to extract the metadata from an existing NFT project on the Internet Computer.

Infinity_Rank The ICPverse service to extract the metadata from an existing NFT project on the Internet Computer. Requirements for Use: npm installed

ICPverse 10 Nov 5, 2022