I have a google cloud function in which I initialize some variables on running the function for the first time so that response will be fast from the next time. The variable values lost when I don't use the function for a certain amount of time which means the function is not running when it's not in use. How can I prevent this?
var browser;
var page;
function getBrowserPage() {
return new Promise(async (resolve, reject) => {
if (!browser) {
browser = await puppeteer.launch({ args: ['--no-sandbox'] });
console.log('Creating a new browser...');
}
if (!page) {
page = await browser.newPage();
console.log('Creating a new page...');
}
resolve(page);
});
}
await getBrowserPage().then(p => {
console.log('page created')
}).catch(err => {
console.log(err)
});