New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

minicache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minicache

A simple cache library for JS/TS. Inspired by [SWR](https://swr.vercel.app/).

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

minicache

A simple cache library for JS/TS. Inspired by SWR.

Installation

npm install minicache

Usage

import { createCache, createMemoryStore } from 'minicache';
const cache = createCache(createMemoryStore());
const result = cache.with(["key"], async (_: string) => "value");
expect(await result.value).toBe("value");

createMemoryStore is a store that uses Map to store the cache. If you want to use with localStorage/sessionStorage, you can use createStorageStore.

import { createCache, createStorageStore } from 'minicache';
const cache = createCache(createStorageStore(window.localStorage));
const result = cache.with(["key"], async (_: string) => "value");
expect(await result.value).toBe("value");

API

createCache(store: Store): Cache

Create a new cache instance.

cache.with(key, fetcher): CachedResult

Fetch the data from the cache or fetcher.

cachedResult.value: Promise<T>

The fetched/cached value.

cachedResult.subscribe(callback: (value: T) => void)

Subscribe to the value change. It returns a function to unsubscribe.

cachedResult.revalidate(): Promise<T>

Revalidate the value with the provided fetcher.

cache.clear()

Clear the cache.

License

MIT

Keywords

FAQs

Package last updated on 18 Feb 2024

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