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

@locmod/cache

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@locmod/cache

quick server cache

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Cache

This library enhances memory-cache module with Typescript support.

Installation

npm install --save @locmod/cache

Usage

import cache from '@locmod/cache'
cache.set
(key: string, data: any, cacheAge?: number) => void

Saves the cache for specific amount of time in ms. If there is undefined, cache will be stored indefinitely.

cache.set('key1', { foo: 'bar' })
cache.set('key2', [1, 2, 3])
cache.set('key3', 'foo', 1000) // 1 second

cache.get
<T>(key: string) => T | null

Gets the saved cache if there is any. If no cache saved for this key, or it's expired, null will be returned. Supports generic types

cache.get('key1') // { foo: 'bar' }
cache.get<number[]>('key2') // [1, 2, 3]
cache.get<string>('key3') // 'foo'

setTimeout(() => {
  cache.get<string>('key3') // null
}, 2000)

cache.keys
() => string[]

Returns all the saved keys

cache.keys() // ['key1', 'key2', 'key3']

cache.clear
(key: string) => void

Removes the saved key

cache.set('foo', 'bar')
cache.get('foo') // bar

cache.clear('foo')
cache.get('foo') // null

cache.clearMatch
(pattern: string) => void

Removes all the saved keys that matches the pattern

cache.set('match-1', 'bar')
cache.set('match-2', 'bar')
cache.set('match-3', 'bar')
cache.set('foo', 'bar')

cache.clearMatch('match-')

cache.get('match-1') // null
cache.get('match-2') // null
cache.get('match-3') // null
cache.get('foo')     // bar

cache.clearAll
() => void

Removes the saved keys

cache.set('match-1', 'bar')
cache.set('match-2', 'bar')
cache.set('match-3', 'bar')
cache.set('foo', 'bar')

cache.clearAll('match-')

cache.get('match-1') // null
cache.get('match-2') // null
cache.get('match-3') // null
cache.get('foo')     // null

Keywords

FAQs

Package last updated on 04 Mar 2022

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