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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ssr-api-cache

v1.5.2

Published

is a caching module for cache data of API and let to backend server to update caches with update data API when occur some changes.

Downloads

5

Readme

ssr-api-cache

is a caching module for cache data of API and let to backend server to update caches with update data API when occur some changes.

useful for SSR (server side render) like React js SSR. ssr-api-cache build an JS file for Client-side render and use Memory for cache data in server side.

ssr-api-cache create update cache API for each api and use nodejs Express for this action.

config

const config = {
   // define update APIs.
   // default: (not required) by default module does not define update API.
   // with this api item server can update cached data in your server when data changed
   // or update cached data manually.
   api: {
       // your express app object.
       // defult: (IS REQUIRED) for have update API.
       // if express undefined then module do not define update API and mean
       // update jusr can be happend with auto update (cache item update property) or restart server.
       express: app,
       // method of update APIs.
       // default : (not required) 'patch'
       method: 'patch',
       // route of API (NOTICE: started and ended with slash)
       // default : (not required) '/api/update/'
       route: '/api/update/',
       // request validation
       // you can use string,array or function to define value.
       // default: (not required) null 
       // value:
       //      null (default) all request is valid.
       //      String: valid ip. exp:'192.168.1.1'
       //      Array [ip1, ip2, ...] list of valid ip. exp: ['192.168.1.1', '192.168.1.2']
       //      Function(req): 
       //              if return true value then valid else is invalid. 
       //              module pass express req object to function.
       validation: null,
   },
   // config client side js file
   // default: (not required) module use default config.
   file: {
       // use for generate unique verion for cache.js file.exp :"cache.js?v=1Ad12s"
       // use process.env.SSRAPICACHE_FILENAME to get file name.
       // each time file change module generatre new hash
       // default: (not required) false 
       // value:
       //      bolean: 
       //          false :do not generate any hash version
       //          true : generate 6 character
       //      number : number of character (like true but with custom hash character number)
       hash: false,
       // file path. start from root of nodejs server.
       // (NOTICE: ended with slash and not exist slash at start)
       // default: (not required) false 'public/'
       path: 'public/',
       // name of file
       // default: (not required) 'cache'
       name: 'cache',
       // extenstion of file. exp: cache.js
       // default: (not required) 'js' 
       extension: 'js'
   },
   // triger when each item of list updated.
   // not trigger for define default value but trigger when his data fetched from API.
   // default: (not required)
   onUpdated: function (cacheItem, newVlaue) {
       console.log(cacheItem.name + " updated to " + JSON.stringify(newVlaue));
   },
   // list of cache items.
   // (IS REQUIRE) at least one item.
   list: [
       {
           // fetch data api
           // default: (IS REQUIRED) full path of api
           // exp: 'http://localhost:3030/api/menu'
           url: 'http://localhost:3030/api/menu',
           // name of cacheItem. 
           // used to access to value with getCache(name) method.
           // default: (IS REQUIRED) string and start with [A-Za-z_$]
           // exp: 'menu'
           name: 'menu',
           // default value of cache item.
           // default: (not required) null 
           // exp: 'default menu'
           default: 'default menu',
           // auto update cache item(milisecond)
           // by default is off.
           // default: (not required) undefined 
           // exp: 86400
           update: 86400 
       },
      // and more ....
   ]
}