【发布时间】:2014-02-24 00:32:27
【问题描述】:
sitemapnode.js 模块的documentation 没有解释cacheTime 是什么。为什么需要生成站点地图?它的目的是什么?
【问题讨论】:
标签: javascript node.js sitemap
sitemapnode.js 模块的documentation 没有解释cacheTime 是什么。为什么需要生成站点地图?它的目的是什么?
【问题讨论】:
标签: javascript node.js sitemap
cacheTime 是 sitemap.js 模块在从提供给它的 url 列表中重新生成 sitemap.xml 文件之前等待的时间。
即。在第一次请求时,会生成一个sitemap.xml 文件并将其放置在缓存中。后续请求从缓存中读取站点地图,直到过期并重新生成。
我同意它可以更清晰,但源代码使其非常清晰。
根据sitemap.js处的源代码,第136行:
// sitemap cache
this.cacheEnable = false;
this.cache = '';
if (cacheTime > 0) {
this.cacheEnable = true;
this.cacheCleanerId = setInterval(function (self) {
self.clearCache();
}, cacheTime, this);
}
和第 187 行:
Sitemap.prototype.toString = function () {
var self = this
, xml = [ '<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
if (this.cacheEnable && this.cache) {
return this.cache;
}
// TODO: if size > limit: create sitemapindex
this.urls.forEach( function (elem, index) {
// SitemapItem
var smi = elem;
具体来说:
if (this.cacheEnable && this.cache) {
return this.cache;
}
清除缓存操作上有一个setInterval,等于给定的cacheTime参数。
请注意,如果您的网址发生更改并且您的 cacheTime 未触发清除站点地图缓存,您的站点地图可能会过期。
【讨论】: