2020-04-29 18:44:27 +03:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const generateFeed = require('./generate-feed');
|
|
|
|
const feedCache = {};
|
2017-11-07 23:00:03 +03:00
|
|
|
|
2017-11-10 10:36:39 +03:00
|
|
|
module.exports.getXML = function getFeedXml(baseUrl, data) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const dataHash = crypto.createHash('md5').update(JSON.stringify(data)).digest('hex');
|
2017-11-10 10:36:39 +03:00
|
|
|
if (!feedCache[baseUrl] || feedCache[baseUrl].hash !== dataHash) {
|
2017-11-07 23:00:03 +03:00
|
|
|
// We need to regenerate
|
2017-11-10 10:36:39 +03:00
|
|
|
feedCache[baseUrl] = {
|
2017-11-07 23:00:03 +03:00
|
|
|
hash: dataHash,
|
2017-11-10 10:36:39 +03:00
|
|
|
xml: generateFeed(baseUrl, data)
|
2017-11-07 23:00:03 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-10 10:36:39 +03:00
|
|
|
return feedCache[baseUrl].xml;
|
2017-11-07 23:00:03 +03:00
|
|
|
};
|