[ develop | DONE | ADDED] Cache services: add initialization method to initiate grouped requests from utils service. Init after clear and when cache starts
This commit is contained in:
parent
a9d06e61fa
commit
629d3efb08
|
@ -1 +1,2 @@
|
||||||
port = 4000
|
port = 4000
|
||||||
|
utilsService = https://beta.explore.openaire.eu/utils-service
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
const axios = require('axios');
|
||||||
let express = require('express');
|
let express = require('express');
|
||||||
let app = express();
|
let app = express();
|
||||||
let mcache = require('memory-cache');
|
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)
|
console.log(`Example app listening on port`, server.address().port)
|
||||||
//run the timer
|
//run the timer
|
||||||
resetAtMidnight();
|
resetAtMidnight();
|
||||||
|
initCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
function getResponse(code, message) {
|
function getResponse(code, message) {
|
||||||
|
@ -155,6 +156,18 @@ function clearCache() {
|
||||||
console.log("cache is cleared!");
|
console.log("cache is cleared!");
|
||||||
mcache.clear();
|
mcache.clear();
|
||||||
entries.set(mcache.size());
|
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) {
|
function checkForLongCachedRequests(url) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"prepare-prod": " npm run prepare-dist; cp production-properties.file ./dist/properties.file"
|
"prepare-prod": " npm run prepare-dist; cp production-properties.file ./dist/properties.file"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.6.7",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"memory-cache": "^0.2.0",
|
"memory-cache": "^0.2.0",
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
port = 4000
|
port = 4000
|
||||||
|
utilsService = https://explore.openaire.eu/utils-service
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
port = 3200
|
port = 3200
|
||||||
|
utilsService= http://scoobydoo.di.uoa.gr:8000
|
||||||
|
|
Loading…
Reference in New Issue