Socket
Book a DemoInstallSign in
Socket

@kaliber/cache

Package Overview
Dependencies
Maintainers
10
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kaliber/cache

Simple memory cache

2.0.1
latest
Source
npmnpm
Version published
Maintainers
10
Created
Source

Cache

Simple memory cache function.

Motivation

Some times you want to cache a value but don't need a complex caching system. This package helps you cache values in side the memory of your application.

Installation

yarn add @kaliber/cache

Usage

import fetch from 'node-fetch'
import { createCache } from '@kaliber/cache'

const cache = createCache({ allowReturnExpiredValue: false, expirationTime: 1000 })

function handleRequest(postId) {
  const data = cache({
    cacheKey: ['post', postId],
    async getValue() {
      const response = await fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`)
      return await response.json()
    }
  })

  return data
}

createCache

PropertyValueDescription
allowReturnExpiredValuefalseif false the expirationTime will be leading in getting results from the cache
allowReturnExpiredValuetrueif true the cache is in 'unsafe' safe mode this means that the cache will always return a value even if the cache time is expired. Of course the cache needs to have a value to get value from it.
expirationTimenumber(in milliseconds) this is the time the cache is valid.

Disclaimer

This library is intended for internal use, we provide no support, use at your own risk.

Keywords

cache

FAQs

Package last updated on 27 May 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.