[ develop | DONE | ADDED] Cache services: add initialization method to initiate grouped requests from utils service. Init after clear and when cache starts

grouped-queries
argirok 3 months ago
parent a9d06e61fa
commit 629d3efb08

@ -1 +1,2 @@
port = 4000
utilsService = https://beta.explore.openaire.eu/utils-service

@ -1,5 +1,5 @@
'use strict';
const axios = require('axios');
let express = require('express');
let app = express();
let mcache = require('memory-cache');
@ -142,6 +142,7 @@ const server = app.listen(properties.get('port'), function () {
console.log(`Example app listening on port`, server.address().port)
//run the timer
resetAtMidnight();
initCache();
});
function getResponse(code, message) {
@ -155,6 +156,18 @@ function clearCache() {
console.log("cache is cleared!");
mcache.clear();
entries.set(mcache.size());
initCache();
}
async function initCache() {
try {
const requests = await axios.get(properties.get('utilsService') + '/grouped-requests');
const additionalDataPromises = requests.data.map((url) => axios.get('http://localhost:'+properties.get('port') + '/get?url=' + properties.get('utilsService') + url));
const additionalDataResponses = await Promise.all(additionalDataPromises);
console.log("Cache initialized!")
} catch (error) {
console.error('Error fetching data: Cache initialize failed', error.message);
}
}
function checkForLongCachedRequests(url) {

@ -10,6 +10,7 @@
"prepare-prod": " npm run prepare-dist; cp production-properties.file ./dist/properties.file"
},
"dependencies": {
"axios": "^1.6.7",
"cors": "^2.8.5",
"express": "^4.18.2",
"memory-cache": "^0.2.0",

@ -1 +1,2 @@
port = 4000
utilsService = https://explore.openaire.eu/utils-service

@ -1 +1,2 @@
port = 3200
utilsService= http://scoobydoo.di.uoa.gr:8000

Loading…
Cancel
Save