file-cached
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

file-cached

Simply cache your object in ./cache.json file.

Release

Usage Example

with obj-cached

import { FileCacheObj } from "file-cached";
import { objCachedAsync } from "obj-cached";

const cacheObj = FileCacheObj(import.meta.dir + "/cache.json");

const result = await objCachedAsync(async () => {
  // do sth heavy
}, cacheObj)();

standalone

import { FileCacheObj } from "file-cached";

const cacheObj = FileCacheObj(import.meta.dir + "/cache.json");

console.log(cacheObj["abc"]); // undefined
// "./cache.json" not existed

cacheObj["abc"] = 123;
// "./cache.json" = {abc: 123}

console.log(cacheObj["abc"]); // 123

cacheObj["def"] = "456";
// "./cache.json" = {abc: 123, def: "456"}

console.log(cacheObj["def"]); // 456

Spec

Check spec here ./index.spec.ts

Readme

Keywords

none

Package Sidebar

Install

npm i file-cached

Weekly Downloads

86

Version

1.2.0

License

ISC

Unpacked Size

10.7 kB

Total Files

9

Last publish

Collaborators

  • snomiao