繁体   English   中英

sitemap node.js模块中的cacheTime是什么?

[英]What is cacheTime in the sitemap node.js module?

sitemap node.js模块的文档没有解释cacheTime是什么。 为什么需要生成站点地图? 它的目的是什么?

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未触发清除站点地图缓存,则您的站点地图可能会过期。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM