Socket
Book a DemoInstallSign in
Socket

@maxdome/cache

Package Overview
Dependencies
Maintainers
15
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maxdome/cache

```javascript const cache = require('@maxdome/cache')(client);

1.0.2
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
15
Weekly downloads
 
Created
Source

Usage

const cache = require('@maxdome/cache')(client);

const value = await cache(
  'key',
  async () => 'value'
);

If the client supports setJSON() and getJSON() (e.g. @maxdome/redis) it will be used to encode/decode the values.

const cache = require('@maxdome/cache')(client);

const value = await cache(
  'key',
  async () => ({ example: 'example' })
);

Expire

An expire (in seconds) can be passed to automatically remove the value from the cache after certain time.

const cache = require('@maxdome/cache')(client);

const value = await cache(
  'key',
  async () => 'value',
  1 * 60 * 60
);

If the expire is an object supporting asSeconds() (e.g. @maxdome/duration or moment.duration) it will be used.

const cache = require('@maxdome/cache')(client);
const duration = require('@maxdome/duration');

const value = await cache(
  'key',
  async () => 'value',
  duration('1h')
);

Invalidate

The invalidate will be called after getting the value from the cache and can, if return true, force to get a new value.

const cache = require('@maxdome/cache')(client);

const value = await cache(
  'key',
  async () => 'value',
  { invalidate: value => value.invalid }
);

Refresh

If refresh is true, the expire will always be refreshed if the key is available and the value is valid.

const cache = require('@maxdome/cache')(client);

const value = await cache(
  'key',
  async () => 'value',
  { refresh: true }
);

FAQs

Package last updated on 25 Feb 2019

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.