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

memo-json

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memo-json

Memoize functions returning JSON by caching results to disk. Useful for applications depending on external resources.

  • 0.1.2
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

memo-json

Memoize functions returning JSON by caching results to disk. Useful for applications depending on external resources.

To install:

npm install memo-json
# or
yarn add memo-json

Usage

// src/data.ts
import { memo } from 'memo-json'

const getDataMemo = memo(function getData(param: string) { ... })

await getDataMemo('a') // Access remote
await getDataMemo('a') // 🥶 Hit cache!
await getDataMemo('b') // Access remote again. A cache key includes function arguments.

The first run of the above code will generate cache like below being reused in the subsequent calls.

# ${process.env.cwd()}/${functionName}-${paramHash}.json
.memo/getRemoteData-4e6c99.json
.memo/getRemoteData-dee827.json

Options

You can own your cusomized memo() funciton by createMemo(opts).

import { createMemo } from "memo-json";

const memo = createMemo({
  dir: "__generated",
  enable: process.env.NODE_ENV !== "production",
});

const getDataMemo = memo(function getData() { ... })

Debug

Debug logs are available when you have DEBUG environment.

DEBUG=memo-json ts-node your-script.ts

# memo-json Cached .memo/xxx-5c9359.json +0ms

Available options:

  • dir - Optional string. ".memo" by default.
  • enable - Optional boolean. true by default.

License

Apache 2.0

Author

Soichi Takamura @piglovesyou

FAQs

Package last updated on 08 Oct 2021

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