diff --git a/src/utils/linkUtils.js b/src/utils/linkUtils.js index 29e25e2..6123ab9 100644 --- a/src/utils/linkUtils.js +++ b/src/utils/linkUtils.js @@ -17,7 +17,19 @@ along with this program. If not, see .*/ //NPM Imports const validator = require('validator');//No express here, so regular validator it is! +//Create link cache +module.exports.cache = new Map(); + module.exports.markLink = async function(link){ + //Check link cache for the requested link + const cachedLink = module.exports.cache.get(link); + + //If we have a cached result + if(cachedLink){ + //return the cached link + return cachedLink; + } + //Set max file size to 4MB const maxSize = 4000000; //Assume links are guilty until proven innocent @@ -66,8 +78,20 @@ module.exports.markLink = async function(link){ }catch{}; } - return { + //Create the link object from processed information + const linkObj = { link, type } + + //Cache the result + module.exports.cache.set(link, linkObj); + + //Set timer to remove cache entry in five minutes + setTimeout(()=>{ + module.exports.cache.delete(link); + }, 300000) + + //return the link + return linkObj; } \ No newline at end of file