node-cache-manager-redis-store
node-cache-manager-redis-store copied to clipboard
How to cache queries?
Hi, this is for sure not an issue, just me not knowing how to use the lib correctly but not sure where to ask besides here... hope it's ok. For some reason I have no problem getting keys (gck:xxx) into Redis but cannot get queries (gcq:xxx) to be cached. (Part of) my test code is as follows:
const NsqlCache = require('nsql-cache');
const dsAdapter = require('nsql-cache-datastore');
const redisStore = require('cache-manager-redis-store');
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const REDISHOST = process.env.REDISHOST || 'localhost';
const REDISPORT = process.env.REDISPORT || 6379;
const cache = new NsqlCache({
db: dsAdapter(datastore),
stores: [{
store: redisStore,
host: REDISHOST,
port: REDISPORT
}],
config: {
ttl: {
keys: 60 * 60, // 1 hour
queries: 0// infinite
}
},
});
ProviderController.list = async function (req, res) {
try {
const providerKey = datastore.key(['V2Provider', '04cb463f-e567-41da-810c-6b918b0130a1']);
const query = datastore.createQuery('V2Provider');
await datastore.get(providerKey); // works fine, stored in Redis DB
const [provs] = await datastore.runQuery(query); //query runs fine but nothing stored in Redis :-(
console.log(provs.length); //60 or so objects, not too much...
res.send({testrun:'ok'});
} catch (error) {
console.log(error);
}
};
I've been through all documentation (afaik) but cannot find what is missing here, so any help would be appreciated!