本文整理匯總了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);
}