Author: wglass Date: Tue Jan 3 21:40:24 2006 New Revision: 365831 URL: http://svn.apache.org/viewcvs?rev=365831&view=rev Log: Here's a better fix to Velocity-98 which caches #include static text separately from templates. Patch as suggested by original contributor Michal Chmielewski. Thanks!
Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?rev=365831&r1=365830&r2=365831&view=diff ============================================================================== --- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java (original) +++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java Tue Jan 3 21:40:24 2006 @@ -16,27 +16,21 @@ * limitations under the License. */ +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Vector; -import java.io.InputStream; -import java.io.IOException; - -import org.apache.velocity.Template; -import org.apache.velocity.runtime.log.Log; -import org.apache.velocity.runtime.RuntimeServices; +import org.apache.commons.collections.ExtendedProperties; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.RuntimeConstants; - -import org.apache.velocity.runtime.resource.ResourceFactory; +import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.runtime.log.Log; import org.apache.velocity.runtime.resource.loader.ResourceLoader; import org.apache.velocity.runtime.resource.loader.ResourceLoaderFactory; import org.apache.velocity.util.ClassUtils; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.apache.velocity.exception.ParseErrorException; - -import org.apache.commons.collections.ExtendedProperties; - /** * Class to manage the text resource for the Velocity * Runtime. @@ -291,27 +285,14 @@ * If it was placed in the cache then we will use * the cached version of the resource. If not we * will load it. - */ - - Resource resource = globalCache.get(resourceName); - - /** - * Check to see if the type has changed and reload the file if so. - * For example, if a file has been loaded with #include and then #parse - * If so, reload the resource. * - * Note that if a page repeatedly alternates #include and #parse - * on the same file the cache is essentially negated. + * Note: the type is included in the key to differentiate ContentResource + * (static content from #include) with a Template. */ - if ( resource != null ) - { - if ( ((resourceType == RESOURCE_CONTENT) && !(resource instanceof ContentResource)) || - ((resourceType == RESOURCE_TEMPLATE) && !(resource instanceof Template)) ) - { - resource = null; - } - } + String resourceKey = resourceType + resourceName; + Resource resource = globalCache.get(resourceKey); + if( resource != null) { /* @@ -330,7 +311,7 @@ * so clear the cache and try again */ - globalCache.remove( resourceName ); + globalCache.remove( resourceKey ); return getResource( resourceName, resourceType, encoding ); } @@ -357,7 +338,7 @@ if (resource.getResourceLoader().isCachingOn()) { - globalCache.put(resourceName, resource); + globalCache.put(resourceKey, resource); } } catch( ResourceNotFoundException rnfe2 ) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]