Velocity模板缓存配置

本文介绍了Velocity模板引擎在线上环境中如何通过配置开启缓存功能,并详细解析了从配置到获取模板过程中涉及的关键代码路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 );
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值