npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

remember-cache

v0.2.0

Published

Two functions inspired by laravel cache::remember managed with localstore

Readme

remember-cache

remember-cache is a simple package that provides few useful functions for managin cache in your javascript project.

These functions are remember, autoUpdate and autoClear

npm i remember-cache

CacheRemember

remember is a function that recieves three parameters, key, time , handler and returns a value. The functionality is very easy, it executes the handler and stores the result in localstorage in base the key that we provide. This key will expire when the time in seconds finish. If we execute from a second time this function with the same key and the time has not expired, it not will trigger the handler so we will save execution time.

This function tries to emulate the functionality of Cache::remember() function from Laravel.

Example

import cache from "remember-cache";

function async apiCall(params){
    //Executes an stressfull api call
    return await myAjaxCaller.get('/idontknow/someurl', params)
}

let result = await cache.remember("store-hi-api-call", 100,()=>{
    return apiCall("hi");
}))
alert(result);

The first time that we execute this example will run more or less at the same speed as usual. However, next time in the next 100 seconds the api call will not be executed so we will get the result instantly. This is useful for apis that get results that usually dont change in a short amount of time or some time-expensive functions that you can easily can store the result.

If we want to improve the speed of our application without compromising too much the validity of the results of our apis we have the following function

CacheAutoupdate

CacheAutoupdate is similar to CacheRemember but it allways executes the handler. However, if it finds that in localstorage we have the key provided it will return a value and execute the handler asynchronously to store the result for the next time that we use it.

The best way to see how it works is with this example

Example

import cache from "remember-cache";
let myArray = ['dubai','bananas','hi','spontiak'];
let results = [];
for(let value in myArray){
    let results.push(cache.autoUpdate('example-key', value))
}

console.log(results)
/*
results (array)
  0 : Promise that will return dubai,
  1 : 'dubai',
  2 : 'bananas',
  3 : 'hi'
*/

As we can see, it always returns the previous element if it exists and if it does not exist it returns a promise with the current element. This is really useful because the already stored items will be retrieved instantly when, for example a user reloads the page. The results may not be the last stored on the server but almost. This can be useful for API calls that often change the results, but getting the latter ones is not too important.