【问题标题】:What is cacheTime in the sitemap node.js module?站点地图 node.js 模块中的 cacheTime 是什么?
【发布时间】:2014-02-24 00:32:27
【问题描述】:

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

【问题讨论】:

    标签: javascript node.js sitemap


    【解决方案1】:

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

    【讨论】:

    • 所以基本上,它是一个处理对创建时提供的 URL 集的修改的功能,对吗?如果是这样,那么如何动态修改此 URL 列表?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 2018-12-09
    • 2019-07-25
    • 2014-11-20
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    相关资源
    最近更新 更多