Search code examples
cachingodatauipathuipath-orchestrator

Disable possible caching of Node.js Orchestrator to return always latest data


I want to get the latest data via odata. So https://uipathspace.com/odata/Robots returns all the robots.

But when I change for instance my robot description:

enter image description here

and refresh https://uipathspace.com/odata/Robots. It shows correctly the updated text:

enter image description here

But I created an application using the node.js Orchestrator implementation. Here I cannot see the description changes:

enter image description here

Is there something hardcore cached and if so how to disable it? I am not able to find that setting.


Solution

  • The problem is that the res.send is put outside of the callback. So it never waits for the actual finish of the REST api call.

    This is the base code where it just took the static result of the first request, it never updated the results:

    app.get('/robots', function (req, res) {
      ...
      var orchestrator = require('./authenticate');
      var results = {};
      var apiQuery= {};
      orchestrator.get('/odata/Robots', apiQuery, function (err, data) {
        for (row in data) {
          results[i] = 
            { 
              'id' : row.id,
              ...
            };
        }
      });  
      return res.send({results});
    });
    

    The solution is to moving the res.send({results}); into the orchestrator.get, then it properly overwrites the results as it waits correctly for the callback:

    app.get('/robots', function (req, res) {
      ...
      var orchestrator = require('./authenticate');
      var results = {};
      var apiQuery= {};
      orchestrator.get('/odata/Robots', apiQuery, function (err, data) {
        for (row in data) {
          results[i] = 
            { 
              'id' : row.id,
              ...
            };
        }
        return res.send({results});
      });  
    });