0.0.12 • Published 12 months ago

@i1k/memory-cache-client v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@i1k/memory-cache-client

npm version codecov

Memory cache client with the same interface as @i1k/smart-cache-manager. Uses lru-cache under the hood.

Installation

# using pnpm
pnpm i @i1k/memory-cache-client

# using npm
npm i @i1k/memory-cache-client

Usage

import MemoryCacheClient from '@i1k/memory-cache-client'

// supports all lru-cache options
const cacheClient = new MemoryCacheClient({ max: 10 })

cacheClient.set('key', 'value')

API Reference

interface ICacheClient {
  set: (key: string, value: string) => Promise<'OK'>
  get: (key: string) => Promise<string | null>
  del: (key: StringOrGlobPattern | StringOrGlobPattern[]) => Promise<string[]>
  clear: () => Promise<string[]>
  keys: (pattern: StringOrGlobPattern | StringOrGlobPattern[]) => Promise<string[]>
}

set

To set a key-value pair.

cacheClient.set('foo', 'bar')
// => Promise<'OK'>

cacheClient.set('foo/main', 'bar')
// => Promise<'OK'>

get

To get a value by key.

cacheClient.get('foo')
// => Promise<'bar'>

cacheClient.get('bar')
// => Promise<null>

del

To delete a key-value pair by a specific key or a glob pattern.

cacheClient.del('foo')
// => Promise<['foo']>

cacheClient.del('foo*')
// => Promise<['foo', 'foo/main']>

cacheClient.del(['foo', 'foo/*'])
// => Promise<['foo', 'foo/main']>

clear

To clear the store.

cacheClient.clear()
// => Promise<['foo', 'foo/main']>

keys

To get keys by a specific key or a glob pattern.

cacheClient.keys('foo')
// => Promise<['foo']>

cacheClient.keys('foo*')
// => Promise<['foo', 'foo/main']>

cacheClient.keys(['foo', 'foo/*'])
// => Promise<['foo', 'foo/main']>

License

MIT

0.0.12

12 months ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago