How many items are you caching, at 1.5mb each?
You could write some nodejs code to do the caching for you. Rather than using the HttpTarget, use a ScriptTarget, and something like this node-cache module to manage the cached items. Have your nodejs logic look in the cache, and return the result if it is present. call the backend only if no cache hit. Like this (assuming express):
var NodeCache = require( "node-cache" );
var myCache = new NodeCache( { stdTTL: 100, checkperiod: 120 } );
var httprequest = require('request');
...
app.get('/objects/:resourceId', function(request, response) {
response.header('Content-Type', 'application/json');
var cacheKey = "resource-" + request.params.resourceId;
myCache.get( cacheKey, function(e, value){
if( !e ){
if(value == undefined){
// key not present, need to call the backend here
var options = {
timeout : 66000, // in ms
uri: 'https://mybackend/whatever/' + request.params.resourceId,
method: 'get',
headers: {
'authorization' : 'maybe something here',
'accept' : 'application/json',
'user-agent' : 'my-nodejs-code'
}
};
httprequest(options, function(e, httpResp, body) {
if (e) {
response.header('Content-Type', 'application/json')
.status(500)
.send({ error: "backend"});
}
else {
myCache.set( cacheKey, body, function(e, success){
// handle error here
response.header('Content-Type', 'application/json')
.status(200)
.send(body);
});
}
});
}
else {
// we have a value, send it back
response.header('Content-Type', 'application/json')
.status(200)
.send(value);
}
}
else {
response.header('Content-Type', 'application/json')
.status(500)
.send({ error: "cache"});
}
});
});
I haven’t tried this, but it seems like it would work. But you need to be careful. If you plan to cache 1000’s of items at 1.5MB each, you’re not gonna have a good time. You will exceed the memory of your system. On the other hand if you are caching 100 items at 1.5MB, that’s probably feasible.
It is also possible to use something like Apigee Edge BaaS for a nearby cache. It is not integrated into the Cache policy, and it does not have an auto-expire capability. But you could use it for that purpose. This would be appropriate if you have lots and lots of objects, which are very large. Usergrid allows you to attach “assets” to an item, and that asset can be binary, and quite large. You would need to write the code that reaps stale entries, yourself.
I prefer the nodejs approach, myself. If it’s appropriate for your purposes, it’s cleaner.