ITeye博客

Velocity模板缓存配置

mini_hu · 2011-03-15 15:30 · Java · 编程语言 · Markdown

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 );
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。