Class WeavedClassCache

java.lang.Object
org.aspectj.weaver.tools.cache.WeavedClassCache

public class WeavedClassCache extends Object
Manages a cache of weaved and generated classes similar to Eclipse Equinox, except designed to operate across multiple restarts of the JVM and with one cache per classloader; allowing URLClassLoaders with the same set of URI paths to share the same cache (with the default configuration).

To enable the default configuration two system properties must be set:

    "-Daj.weaving.cache.enabled=true"
    "-Daj.weaving.cache.dir=/some/directory"
 

The class cache is often something that application developers or containers would like to manage, so there are a few interfaces for overriding the default behavior and performing other management functions.

CacheBacking
Provides an interface for implementing a custom backing store for the cache; The default implementation in DefaultFileCacheBacking provides a naive file-backed cache. An alternate implementation may ignore caching until signaled explicitly by the application, or only cache files for a specific duration. This class delegates the locking and synchronization requirements to the CacheBacking implementation.

CacheKeyResolver
Provides methods for creating keys from classes to be cached and for creating the "scope" of the cache itself for a given classloader and aspect list. The default implementation is provided by DefaultCacheKeyResolver but an alternate implementation may want to associate a cache with a particular application running underneath a container.

This naive cache does not normally invalidate *any* classes; the interfaces above must be used to implement more intelligent behavior. Cache invalidation problems may occur in at least three scenarios:

  1. New aspects are added dynamically somewhere in the classloader hierarchy; affecting other classes elsewhere.
  2. Use of declare parent in aspects to change the type hierarchy; if the cache has not invalidated the right classes in the type hierarchy aspectj may not be reconstruct the class incorrectly.
  3. Similarly to (2), the addition of fields or methods on classes which have already been weaved and cached could have inter-type conflicts.