/*
registers that a request came into the cache for a cacheable object

@param template the template of the cache entry. The template cannot be null for Servlet cache.

@param source whether the invalidation was generated internally or remotely
337286
public void onRequest(String template, int source) {
        final String methodName = "onRequest()";

        CacheStatsModule csm = null;
        if ((csm = getCSM(template)) == null) {
            return;
        }
        if (tc.isDebugEnabled())
            Tr.debug(tc, methodName + " cacheName=" + _sCacheName + " template=" + template + " source=" + source + " enable=" + csm._enable + " "
                    + this);
        if (csm._enable) {
            if (source == LOCAL) {
                if (csm._clientRequestCount != null)
                    csm._clientRequestCount.increment();
            } else if (source == REMOTE) {
                if (csm._distributedRequestCount != null)
                    csm._distributedRequestCount.increment();
            }
        }
        return;
    }
1131760
public function putTemplate($cacheKey, Template $template)
    {
        if ($template->getCacheTime() == null && !is_numeric($template->getCacheTime()))
            $template->setCacheTime($this->defaultCacheTime);

        $this->put($cacheKey, $template, (int)$template->getCacheTime());

        return true;
    }
442947
function getSourceTemplate(cb) {
    if (options.cache) {
      var info = self.cache[filename];
      if (info) {
        return cb(null, info.source, info.template);
      }
    }

    fs.readFile(filename, 'utf8', function(err, source) {
      if (err) return cb(err);

      var template = self.compile(source, filename);
      if (options.cache) {
        self.cache[filename] = {
          source: source,
          template: template
        };
      }
      return cb(null, source, template);
    });
  }
200823
public static TemplateMetadata fromTemplate(TemplateNode template) {
    TemplateMetadata.Builder builder =
        builder()
            .setTemplateName(template.getTemplateName())
            .setSourceLocation(template.getSourceLocation())
            .setSoyFileKind(SoyFileKind.SRC)
            .setContentKind(template.getContentKind())
            .setStrictHtml(template.isStrictHtml())
            .setDelPackageName(template.getDelPackageName())
            .setVisibility(template.getVisibility())
            .setParameters(Parameter.directParametersFromTemplate(template))
            .setDataAllCallSituations(DataAllCallSituation.fromTemplate(template));
    switch (template.getKind()) {
      case TEMPLATE_BASIC_NODE:
        builder.setTemplateKind(Kind.BASIC);
        break;
      case TEMPLATE_DELEGATE_NODE:
        builder.setTemplateKind(Kind.DELTEMPLATE);
        TemplateDelegateNode deltemplate = (TemplateDelegateNode) template;
        builder.setDelTemplateName(deltemplate.getDelTemplateName());
        builder.setDelTemplateVariant(deltemplate.getDelTemplateVariant());
        break;
      case TEMPLATE_ELEMENT_NODE:
        builder.setTemplateKind(Kind.ELEMENT);
        break;
      default:
        throw new AssertionError("unexpected template kind: " + template.getKind());
    }
    return builder.build();
  }
473419
protected void mergeTemplate (Template template, InvocationContext context)
        throws ResourceNotFoundException, ParseErrorException, MethodInvocationException,
               UnsupportedEncodingException, IOException, Exception
    {
        HttpServletResponse response = context.getResponse();
        ServletOutputStream output = response.getOutputStream();
        // ASSUMPTION: response.setContentType() has been called.
        String encoding = response.getCharacterEncoding();

        VelocityWriter vw = null;
        try {
            vw = (VelocityWriter)_writerPool.get();
            if (vw == null) {
                vw = new VelocityWriter(new OutputStreamWriter(output, encoding), 4 * 1024, true);
            } else {
                vw.recycle(new OutputStreamWriter(output, encoding));
            }
            template.merge(context, vw);

        } catch (IOException ioe) {
            // the client probably crashed or aborted the connection ungracefully, so use log.info
            log.info("Failed to write response", "uri", context.getRequest().getRequestURI(),
                     "error", ioe);

        } finally {
            if (vw != null) {
                try {
                    // flush and put back into the pool don't close to allow us to play nicely with
                    // others.
                    vw.flush();
                } catch (IOException e) {
                    // do nothing
                }

                // Clear the VelocityWriter's reference to its internal OutputStreamWriter to allow
                // the latter to be GC'd while vw is pooled.
                vw.recycle(null);
                _writerPool.put(vw);
            }
        }
    }
733510
private final CompiledST loadTemplateResource(String prefix, String unqualifiedFileName) {
        //if (resourceRoot == null) return null;
        //return loadTemplate(resourceRoot, prefix, unqualifiedFileName);
        if (resourceRoots.isEmpty()) return null;
        CompiledST template = null;
        for (URL resourceRoot : resourceRoots) {
            if ((template = loadTemplate(resourceRoot, prefix, unqualifiedFileName)) != null)
                return template;
        }
        return null;
    }
513584
@Deprecated
	public static void removeTemplate(Client client, String template) {
		logger.trace("removeTemplate({})", template);
		client.admin().indices().prepareDeleteTemplate(template).get();
		logger.trace("/removeTemplate({})", template);
	}
987625
public String process(String templateName, String templateSource, Map<String, Object> params) {
        try {
            Template template = new Template(templateName, templateSource, configuration);
            Writer writer = new StringWriter();
            template.process(params, writer);
            return writer.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
224623
public void delTemplate(String template) {
        if (htod.delTemplate(template) == HTODDynacache.DISK_EXCEPTION) {
            stopOnError(this.htod.diskCacheException);
        }
    }
496611
public Context setTemplate(Template template) {
        checkThread();
        if (template != null) {
            setEngine(template.getEngine());
        }
        this.template = template;
        return this;
    }
1238746
public int writeTemplateEntry(String template, Object entry) {
        int returnCode = htod.writeTemplateEntry(template, entry);
        if (returnCode == HTODDynacache.DISK_EXCEPTION) {
            stopOnError(this.htod.diskCacheException);
        }
        return returnCode;
    }
912192
protected void doRequest (HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
    {
        InvocationContext context = null;
        try {
            context =  new InvocationContext(request, response);
            setContentType(request, response);

            Template template = handleRequest(request, response, context);
            if (template != null) {
                mergeTemplate(template, context);
            }

        } catch (Exception e) {
            log.warning("doRequest failed", "uri", request.getRequestURI(), e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        }
    }
1325050
public static boolean isTemplateExist(RestClient client, String template) throws IOException {
		Response response = client.performRequest(new Request("HEAD", "/_template/" + template));
		return response.getStatusLine().getStatusCode() == 200;
	}
1139603
public void setTemplate(String template) throws MissingIncludeException {
	PageSource ps = pageContext.getCurrentPageSource().getRealPage(template);
	if (!ps.exists()) throw new MissingIncludeException(ps);
	errorPage.setTemplate(ps);
    }
1228429
def check_cache(self, template):
        '''
        
        '''
        if template not in self.cached:
            self.cache_file(template)
            self.cached.append(template)
800465
public String renderIfTemplateExists(String template, Object... args) {
        boolean typeInferenceEnabled = conf().typeInferenceEnabled();
        if (typeInferenceEnabled) {
            ParamTypeInferencer.registerParams(this, args);
        }

        if (nonExistsTemplates.contains(template)) return "";

        String key = template;
        if (typeInferenceEnabled) {
            key += ParamTypeInferencer.uuid();
        }

        try {
            TemplateClass tc = classes().getByTemplate(template);
            if (null == tc) {
                ITemplateResource rsrc = resourceManager().getResource(template);
                if (rsrc.isValid()) {
                    tc = new TemplateClass(rsrc, this);
                    //classes().add(key, tc);
                } else {
                    nonExistsTemplates.add(template);
                    if (isDevMode() && nonExistsTemplatesChecker == null) {
                        nonExistsTemplatesChecker = new NonExistsTemplatesChecker();
                    }
                    return "";
                }
            }
            ITemplate t = tc.asTemplate(this);
            setRenderArgs(t, args);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
973026
function addTemplateToCompiler (mainCompiler, templatePath) {
  const childCompiler = getChildCompiler(mainCompiler);
  const isNew = childCompiler.addTemplate(templatePath);
  if (isNew) {
    clearCache(mainCompiler);
  }
}