Jér*_*nge 6 javascript sitemap node.js
该文档的的sitemap node.js模块并不能说明什么cacheTime是.为什么需要生成站点地图?它的目的是什么?
这是 sitemap.js 模块从给定的 url 列表cacheTime重新生成文件之前等待的时间。sitemap.xml
IE。在第一个请求时,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);
}
Run Code Online (Sandbox Code Playgroud)
和第 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;
Run Code Online (Sandbox Code Playgroud)
具体来说:
if (this.cacheEnable && this.cache) {
return this.cache;
}
Run Code Online (Sandbox Code Playgroud)
并且清除缓存操作有一个setInterval等于cacheTime给定参数的值。
请注意,如果您的网址发生更改并且cacheTime未触发站点地图缓存的清除,则您的站点地图可能会过时。
| 归档时间: |
|
| 查看次数: |
699 次 |
| 最近记录: |