@@ -167,15 +167,21 @@ export async function getVTReleaseStats(req) {
167167/**
168168 * Get VT Stats for a File ID/Hash
169169 * @param {string } hash
170- * @return {Promise<object> }
170+ * @typedef {object } Stats
171+ * @property {number } malicious
172+ * @property {number } suspicious
173+ * @property {number } undetected
174+ * @return {Promise<Stats> }
171175 */
172176export async function getVTStats ( hash ) {
173177 const key = `/vt/id/${ hash } `
178+ const timeout = 60 * 60 * 24 * 5
174179 debug ( 'key:' , key )
175180 // NOTE: Duplicate Code - 5 lines
176181 const cached = await cacheGet ( key )
177182 if ( cached ) {
178183 if ( cached . errorMessage ) throw new Error ( cached . errorMessage )
184+ client . expire ( key , timeout ) . catch ( console . error ) // reset expire on get
179185 return cached
180186 }
181187 debug ( `-- CACHE MISS: ${ key } ` )
@@ -195,7 +201,7 @@ export async function getVTStats(hash) {
195201 stats = data ?. data ?. attributes ?. last_analysis_stats
196202 }
197203 if ( ! stats ) await cacheError ( key , 'VT Stats Not Found' )
198- await cacheSet ( key , stats , 60 * 60 * 48 )
204+ await cacheSet ( key , stats , timeout )
199205 return stats
200206}
201207
@@ -275,6 +281,16 @@ export async function incrKey(key) {
275281 await client . incr ( key )
276282}
277283
284+ // export async function incrPurge(result) {
285+ // const multi = client.multi().incr('purge_count')
286+ // // multi.incr('purge_count')
287+ // if (result) {
288+ // multi.incr('purge_hit')
289+ // } else {
290+ // multi.incr('purge_miss')
291+ // }
292+ // }
293+
278294export async function sendInflux ( ) {
279295 if ( ! influxClient ) return debug ( 'InfluxDB Not Configured.' )
280296 debug ( `Processing Influx: ${ new Date ( ) . toLocaleString ( ) } ` )
0 commit comments