1.5.2 • Published 5 years ago

ssr-api-cache v1.5.2

Weekly downloads
41
License
-
Repository
-
Last release
5 years ago

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 ....
   ]
}
1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago