Caching has been mostly working and pretty stable for the last few months, with a solution like this:
app.remotes().before('Asset.expensiveOp', (ctx, next) => {
const {res} = ctx
// lookup in cache
// if found, return it
if (found) {
res.send(result)
// if not found, override send to receive the response
} else {
const send = res.send
res.send = function(result) {
cacheResult(result)
send.call(this, result)
}
// then run the function
next()
}
})
I now want to get the id and timestamp that auto-generated for the cached object. So I'd like to do something like this:
However, overriding res.send with anything asynchronous won't work, because in Strong Remoting res.end is called immediately after res.send (Code Here).
Is there an existing after middleware that I'm missing that would work with an async operation? I'd prefer to stick to app.remotes() in order to keep this logic at a consistent layer. But just about anything would be better than monkey patching res.send. :-)
Yet another case of trying to implement caching. :-)
Caching has been mostly working and pretty stable for the last few months, with a solution like this:
I now want to get the
id
andtimestamp
that auto-generated for the cached object. So I'd like to do something like this:However, overriding
res.send
with anything asynchronous won't work, because in Strong Remotingres.end
is called immediately afterres.send
(Code Here).Is there an existing
after
middleware that I'm missing that would work with an async operation? I'd prefer to stick toapp.remotes()
in order to keep this logic at a consistent layer. But just about anything would be better than monkey patchingres.send
. :-)