velocity开启缓存,主要用于线上环境,在velocity.properties中
拨开读取模板代码:
file.resource.loader.cache = true
file.resource.loader.modificationCheckInterval = -1
拨开读取模板代码:
Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding);
VelocityResult.java :
protected Template getTemplate(ValueStack stack, VelocityEngine velocity, ActionInvocation invocation, String location, String encoding) throws Exception {
if (!location.startsWith("/")) {
location = invocation.getProxy().getNamespace() + "/" + location;
}
Template template = velocity.getTemplate(location, encoding);
return template;
}
VelocityEngine.java
public Template getTemplate(String name, String encoding)
throws ResourceNotFoundException, ParseErrorException, Exception
{
return ri.getTemplate( name, encoding );
}
RuntimeInstance.java
public Template getTemplate(String name, String encoding)
throws ResourceNotFoundException, ParseErrorException, Exception
{
requireInitialization();
return (Template)
resourceManager.getResource(name,
ResourceManager.RESOURCE_TEMPLATE, encoding);
}
ResourceManagerImpl.java
public Resource getResource(final String resourceName, final int resourceType, final String encoding)
throws ResourceNotFoundException,
ParseErrorException,
Exception
{
String resourceKey = resourceType + resourceName;
Resource resource = globalCache.get(resourceKey);
ResourceCacheImpl.java
public Resource get( Object key )
{
return (Resource) cache.get( key );
}