本文整理汇总了TypeScript中node-cache.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getTrends
function getTrends(woeid, callback) {
console.log('trend request for', woeid)
var cacheKey = 'trend_' + woeid;
var cachedTrends = myCache.get(cacheKey);
if (!cachedTrends[cacheKey]) {
console.log('refreshing cache trends');
tApi.get('/trends/place', {
id: woeid
}, function (err, data) {
if (err) {
console.log(err);
throw err;
}
myCache.set(cacheKey, data[0]);
callback(data[0].trends)
});
} else {
console.log('returning trends from cache')
callback(cachedTrends[cacheKey].trends);
}
}
示例2: async
const getUsersAlbums = async (req: any, res: any) => {
const url: string = "http://graph.facebook.com/" + req.params.userId +
"?fields=albums.fields(id,name,created_time,photos.fields(id,name,picture,source,created_time).limit(5000))";
const albumIds: string[] = req.query["ids"] ? req.query["ids"].split(",") : null;
const key: string = req.originalUrl;
let albumsJson: string = await nodeCache.get(key);
if(albumsJson){
res.setHeader("Access-Control-Allow-Origin", "*");
res.writeHead(200, { "Content-Type": "application/json" });
//console.log(albumsJson);
res.end(albumsJson);
}
else{
facebook.api(url, (err, data): void => {
let albums: Album[] = [];
if(err) facebookApiErrorHandler(res, err);
else albums = facebookApiSuccessHandler(albumIds, data);
albumsJson = Album.albumArrayToJson(albums);
res.setHeader("Access-Control-Allow-Origin", "*");
res.writeHead(200, { "Content-Type": "application/json" });
//console.log(albumsJson);
res.end(albumsJson);
nodeCache.set(key, albumsJson);
});
}
};
示例3: function
app.get('/api/jobservice', function (req,response){
myCache.get( "jobs", function( err, value ){
if( !err ){
if(value == undefined){
console.log("undifined");
response.status(404).send("Job List Not Available");
}else{
response.send(value);
}
}
});
});
示例4: Strategy
passport.use(new Strategy(params, function (payload: IUserSession, done) {
/*
La estrategia es tener un listado de Token validos en la db y validar contra eso.
Podemos invalidar un token desde la db, usando Token.valid.
Pero para no esta leyendo permanentemente en la db, usamos un cacheLocal que nos
mantiene 1 hora los tokens en memoria, luego de esa hora se vuelven a leer desde la db.
*/
const cachedSession = sessionCache.get(payload.token_id);
if (cachedSession && cachedSession === payload.id) {
return done(undefined, payload);
} else {
Token.findById(payload.token_id, function (err: any, token: IToken) {
if (err || !token || !token.valid || !(token.usuario as any).equals(payload.id)) {
return done(undefined, false, {
message: "Invalid Token"
});
}
sessionCache.set(token.id, token.usuario.toString());
return done(undefined, payload);
});
}
}));
示例5: get
get(key: string | number) {
return this.cache.get(key);
}