读书人

Velocity模板缓存配备

发布时间: 2012-12-26 14:39:29 作者: rapoo

Velocity模板缓存配置
velocity开启缓存,主要用于线上环境,在velocity.properties中

file.resource.loader.cache = truefile.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.javapublic Template getTemplate(String name, String encoding)        throws ResourceNotFoundException, ParseErrorException, Exception    {        return ri.getTemplate( name, encoding );    }RuntimeInstance.javapublic Template getTemplate(String name, String  encoding)        throws ResourceNotFoundException, ParseErrorException, Exception    {        requireInitialization();        return (Template)                resourceManager.getResource(name,                    ResourceManager.RESOURCE_TEMPLATE, encoding);    }ResourceManagerImpl.javapublic 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.javapublic Resource get( Object key )    {        return (Resource) cache.get( key );    }

读书人网 >编程

热点推荐