@senar/loadonce
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Loadonce

中文

Cache your any resource, load once!

install

pnpm install @senar/loadonce

usage

cache one source

import loadonce from '@senar/loadonce'

const resourceUrl = 'your-source-url, could be fetch'
const resource = await loadonce(resourceUrl)
// twice load will be fast, cached
const resource1 = await loadonce(resourceUrl)

cache some source

import loadonce from '@senar/loadonce'

const resourceUrls = ['https://one', 'https://two']
const resource = await loadonce(resourceUrls)
// twice load will be fast, cached
const resource1 = await loadonce(resourceUrls)

when clear?

limit key's count

import loadonce, { setMaxKeyCount } from '@senar/loadonce'

setMaxKeyCount(100) // limit max key count: 100

// if loadonce cache over 100, will clear all cache.
const resource = await loadonce('...')

limit cache's size

import loadonce, { setMaxCacheSize } from '@senar/loadonce'

setMaxCacheSize(1024 * 1024 * 1024) // limit max size 1GB 1024 * 1024 * 1024 bytes

// if loadonce cache size over 1024 * 1024 * 1024 bytes, will clear all cache.
const resource = await loadonce('...')

Package Sidebar

Install

npm i @senar/loadonce

Weekly Downloads

0

Version

0.0.1

License

none

Unpacked Size

5.56 kB

Total Files

7

Last publish

Collaborators

  • senar