New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cache-client-promise

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-client-promise

client side cache

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Cache Client Promise

Coverage Status

simple client-side cache module. helps especially when requests are being fired so fast that the same request can be fired before the same request finishes.

Why?

A lot of tutorials and what not are solid and advise well on client side cacheing strategies. I needed a more generic cache that I could use with promises, and that could handle the scenario that if a request was fired off, and the same request was made before the first one finished, you could still get the result of the first request.

Usage


import CacheClientPromise from 'cache-client-promise'

const myCache = new CacheClientPromise();

myCache.get('article-12345', function () {
  return fetch(`/api/articles/12345`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json'
    },
    credentials: 'same-origin'
  })
    .then(response => response.json())
})
  .then((article) => {
    //do something with the article
  })
  .catch((reason) => {
    //something happened most likely in your requesting function
  })

check out the tests in the repo for more examples!

This will check the cache for the key that you give to it, and if already there, will resolve immediately.

If it is not yet in the cache, it will add your cache key to it's list, where it keeps a list of internal promises of everything that requests this key.

When the first request for the key finally resolves, it will look at the promises that have been stored for itself internally and resolve them.

FAQs

Package last updated on 29 Aug 2017

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