@@ -224,7 +224,7 @@ const mapToUniprotIds = biopaxTemplate => {
224224      if  (  dbPrefix  !==  'ncbigene'  ) { 
225225        return  Promise . resolve ( ) ; 
226226      } 
227-        
227+ 
228228      const  UNIPROT_DB_PREFIX  =  'uniprot' ; 
229229      const  opts  =  { 
230230        id : [ 
@@ -1441,26 +1441,32 @@ http.get('/(:id).png', function( req, res, next ){
14411441
14421442  res . setHeader ( 'content-type' ,  'image/png' ) ; 
14431443
1444-   const  fillCache  =  async  ( doc ,  lastEditedDate )  =>  { 
1444+   const  calcTtl  =  doc  =>  { 
1445+     const  now  =  Date . now ( ) ; 
1446+     const  lastEditedDate  =  doc . lastEditedDate ( ) ; 
1447+     return  now  -  lastEditedDate ; 
1448+   } ; 
1449+ 
1450+   const  fillCache  =  async  doc  =>  { 
14451451    const  img  =  await  getDocumentImageBuffer ( doc ) ; 
1446-     const  cache  =  {  img,  lastEditedDate } ; 
1452+     const  cache  =  {  img } ; 
1453+     const  ttl  =  calcTtl ( doc ) ; 
14471454
1448-     imageCache . set ( id ,  cache ) ; 
1455+     imageCache . set ( id ,  cache ,   { ttl } ) ; 
14491456
14501457    return  cache ; 
14511458  } ; 
14521459
14531460  const  main  =  async  ( )  =>  { 
14541461    try  { 
1455-       const  doc  =  await  getDoc ( id ) ; 
1456-       const  lastEditedDate  =  ''  +  doc . lastEditedDate ( ) ; 
1457-       const  cache  =  imageCache . get ( id ) ; 
1458-       const  canUseCache  =  imageCache . has ( id )  &&  cache . lastEditedDate  ===  lastEditedDate ; 
1462+       const  canUseCache  =  imageCache . has ( id ) ; 
14591463
14601464      if (  canUseCache  ) { 
1465+         const  cache  =  imageCache . get ( id ) ; 
14611466        res . send ( cache . img ) ; 
14621467      }  else  { 
1463-         const  cache  =  await  fillCache ( doc ,  lastEditedDate ) ; 
1468+         const  doc  =  await  getDoc ( id ) ; 
1469+         const  cache  =  await  fillCache ( doc ) ; 
14641470
14651471        res . send ( cache . img ) ; 
14661472      } 
0 commit comments