Skip to content

add caching #252

@trickydisco78

Description

@trickydisco78

Anyone managed to add caching to the onProxyReq option?

I've added a memory caching function to onProxyReq

proxy middleware configuration

var cache = duration => {
  return (proxyReq, req, res) => {
    let key = '__express__' + proxyReq.path || proxyReq.url;
    //console.log(proxyReq);
    console.log(key);
    let cachedBody = mcache.get(key);
    console.log(cachedBody);
    if (cachedBody) {
      console.log('use cache');
      res.send(cachedBody);
      return;
    } else {
      console.log('set cache');
      //console.log(body);
      console.log(res.send);
      res.sendResponse = res.send;
      res.send = body => {
        console.log(body);
        mcache.put(key, body, duration * 5000);
        console.log('set cache');
        res.sendResponse(body);
        return;
      };
    }
  };
};

onProxyReq: cache(10),

It looks like it's not grabbing the body information or getting to set the cache at

mcache.put(key, body, duration * 5000);

body comes up as null as wel

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions