有一个npm包,允许您缓存对redis的axios get调用。看完文档后,我似乎无法将其缓存到redis。我正在使用推荐的axios 0.18.1
版本,但仍然没有喜悦。我错过了什么?
// Set-up code
const Axios = require('axios');
const Cache = require('axios-cache-adapter');
const Redis = require('redis');
const redis = Redis.createClient(); // using localhost
const redisStore = new Cache.RedisStore(redis);
const cacheMe = Cache.setupCache({
maxAge: 30 * 60 * 1000,
store: redisStore,
exclude: {
query: false
},
debug: true
});
const axios = Axios.create({
cache: cacheMe.adapter
});
// Snippet of axios call fromCache is always undefined
async resolve(root) {
const url = solrApi.getReports({ id: root.id });
const resp = await axios.get(url);
console.log(`Found ${ resp.data.response.numFound } record(s) in ${ resp.data.responseHeader.QTime } ms (fromCache: ${ resp.request.fromCache }`);
return resp.data.response.docs;
}
暂无答案!
目前还没有任何答案,快来回答吧!