2017-11-07 23:00:03 +03:00
|
|
|
var crypto = require('crypto'),
|
|
|
|
generateFeed = require('./generate-feed'),
|
|
|
|
feedCache = {};
|
|
|
|
|
2017-11-10 10:36:39 +03:00
|
|
|
module.exports.getXML = function getFeedXml(baseUrl, data) {
|
2017-11-07 23:00:03 +03:00
|
|
|
var 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
|
|
|
};
|