@fallroot/ttlize

0.0.1 • Public • Published

TTLize

This is a JavaScript library for timeout based memoization. It uses my another library SandStorage for supporting Web Storage. It also detects Promises.

Usage

ttlize(fn, [ttl=0], [options={}]);

Creates a function that memoizes the result of fn. It memoizes result during the ttl value. After ttl is passed, fn is executed and memoizes result again. You can save the memoized result to Web Storage for using in multiple pages.

Parameters

  • fn(Function): The function to ttlize.
  • [ttl=0](Integer): The number of milliseconds to maintain memoization.
  • [options={}](Object): The options object.
  • [options.type](String): 'localStorage' or 'SessionStorage'.
  • [options.key](String): The name of key using for Web Storage.

Returns

Returns the new ttlized function. If fn is Promises object then returns then() call.

ttlize($.ajax, 1000)().then(...);

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i @fallroot/ttlize

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • fallroot