示例#1
0
function sectionCache(req, res, cacheKey, section, templateName, layoutConfig, theme, next) {

  calipso.cacheService.check(cacheKey, function (err, isCached) {
    if (isCached) {
      calipso.silly("Cache hit for " + cacheKey + ", section " + section);
      calipso.cacheService.get(cacheKey, function (err, cache) {
        if (!err) {
          res.bufferedOutput[section] = cache.content;
        }
        next(err);
      });
    } else {
      calipso.silly("Cache miss for " + cacheKey + ", section " + section);
      processSection(req, res, section, templateName, layoutConfig, theme, function (err) {
        if (!err) {
          var content = res.bufferedOutput[section];
          calipso.cacheService.set(cacheKey, {
            content:content
          }, null, next);
        } else {
          next(err);
        }
      });
    }
  });
}
示例#2
0
 processSection(req, res, section, templateName, layoutConfig, theme, function (err) {
   if (!err) {
     var content = res.bufferedOutput[section];
     calipso.cacheService.set(cacheKey, {
       content:content
     }, null, next);
   } else {
     next(err);
   }
 });
示例#3
0
RenderedBlocks.prototype.set = function (block, content, layout, params, next) {

  var cacheKey = calipso.cacheService.getCacheKey(['block', block], params);

  this.content[block] = this.content[block] || [];
  this.content[block].push(content);

  // If we are caching, then cache it.
  if (this.contentCache[block]) {
    calipso.silly("Cache set for " + cacheKey);
    this.cache.set(cacheKey, {
      content:content,
      layout:layout
    }, null, next);
  } else {
    next();
  }

};
示例#4
0
function processTheme(req, res, layout, theme, next) {

  var layoutConfig, copyConfig, copySection, sectionExists, disable, sections = [],
    section;

  delete res.bufferedOutput;
  res.bufferedOutput = {};

  // Scan through each layout
  try {
    layoutConfig = theme.config.layouts[layout].layout;
  } catch (ex) {
    next(ex.message);
    return;
  }

  // Check to see if this layout copies default
  if (layoutConfig.copyFrom && layout != "default") {

    copyConfig = theme.config.layouts[layoutConfig.copyFrom].layout;
    layoutConfig.sections = layoutConfig.sections || {};

    // Copy over any missing sections from default
    for (copySection in copyConfig.sections) {

      sectionExists = layoutConfig.sections && layoutConfig.sections[copySection];
      disable = layoutConfig.sections && layoutConfig.sections[copySection] && layoutConfig.sections[copySection].disable;
      if (!sectionExists && !disable) {
        layoutConfig.sections[copySection] = copyConfig.sections[copySection];
        layoutConfig.sections[copySection].layout = "default"; // Flag override as below
      }

    }

  }

  // Create a section array
  for (section in layoutConfig.sections) {
    disable = layoutConfig.sections[section].disable;
    if (!disable) {
      sections.push(section);
    }
  }
  var totalCount = sections.length;
  var totalDone = 0;

  // Now, process all the sections
  // This is done via a localNext to give us full control
  //   and better ability to debug

  function localNext(err) {
    totalDone += 1;

    if (totalDone == totalCount) {
      next();
    }

  }

  for (section in layoutConfig.sections) {

    // Check to see if we are overriding
    var currentSection = section;
    var layoutOverride = layoutConfig.sections[section].layout;
    var sectionPath = layoutOverride ? layoutOverride + "." + section : layout + "." + section;
    var cache = layoutConfig.sections[section].cache;
    var params = layoutConfig.sections[section].varyParams;
    var cacheEnabled = calipso.config.get('performance:cache:enabled');
    var isAdmin = req.session.user && req.session.user.isAdmin;

    disable = layoutConfig.sections[section].disable;

    // Sections are cacheable
    if (!disable) {
      if (cache && cacheEnabled && !isAdmin) {
        var keys = [layout, 'section', currentSection];
        var cacheKey = calipso.cacheService.getCacheKey(keys, params);
        sectionCache(req, res, cacheKey, section, sectionPath, layoutConfig, theme, localNext);
      } else {
        processSection(req, res, section, sectionPath, layoutConfig, theme, localNext);
      }
    }

  }

}