Temporal cache to add values that are updated after certain time.

By @mantradev

Install with:

$ mantrad download-component tempcache@1.0.0

Or install last version with:

$ mantrad download-component tempcache


tempcache Mantra component

Simple memory cache based on key / values pairs which remembers the values cached a certain time. When reached this time, the entry stored at the cache is removed.

API exposed by tempcache

async Mantra.api.tempcache.get( Mantra, options )

Gets a value cached. If it is new or seconds has been ellapsed when was created, the value is updated.


  • Mantra: Mantra API object instance.
  • options: object with the following properties:
    • key: <key for the value>,
    • seconds: <seconds for the value to be updated, optional, default: 3600 (1 hour)>,
    • fncUpdate: <function: async (Mantra, params) => () function to be called for update the value >,
    • fncParams: <params to used when calling fncUpdate, optional>


await Mantra.api.tempcache.get( Mantra, 'usersesiontoken', {
    seconds: 60*10,
    fncUpdate: async (Mantra) => { return getNewUserToken() }

This sample generates a cache key named as 'usersesiontoken' and it is stored as much as 10 minutes. After this time, the next time the method is called, them the component updates its value or get a new one calling the function indicated at fncUpdate.