org.aspectj.weaver.tools.cache
Class DefaultFileCacheBacking

java.lang.Object
  extended by org.aspectj.weaver.tools.cache.DefaultFileCacheBacking
All Implemented Interfaces:
CacheBacking

public class DefaultFileCacheBacking
extends java.lang.Object
implements CacheBacking

Naive File-Backed Class Cache with no expiry or application centric invalidation.

Enabled with the system property, "aj.weaving.cache.dir" If this system property is not set, no caching will be performed.

A CRC checksum is stored alongside the class file to verify the bytes on read. If for some reason there is an error reading either the class or crc file, or if the crc does not match the class data the cache entry is deleted.

An alternate implementation of this could store the class file as a jar/zip directly, which would have the required crc; as a first pass however it is somewhat useful to view these files in expanded form for debugging.


Nested Class Summary
static class DefaultFileCacheBacking.IndexEntry
           
 
Field Summary
static java.lang.String INDEX_FILE
           
static java.lang.String WEAVED_CLASS_CACHE_DIR
           
 
Constructor Summary
protected DefaultFileCacheBacking(java.io.File cacheDirectory, CacheKeyResolver resolver)
           
 
Method Summary
 void clear()
          Clear the entire cache
protected static void close(java.io.InputStream in, java.io.File file)
           
protected static void close(java.io.OutputStream out, java.io.File file)
           
static CacheBacking createBacking(java.io.File cacheDir, CacheKeyResolver resolver)
           
static CacheBacking createBacking(java.lang.String scope, CacheKeyResolver resolver)
           
protected static void delete(java.io.File file)
           
 CachedClassEntry get(CachedClassReference ref)
          Get a cache entry
 java.lang.String[] getKeys(java.lang.String regex)
          Return a list of keys which match the given regex.
 void put(CachedClassEntry entry)
          Put an entry in the cache
protected  byte[] read(java.io.File file, long expectedCRC)
           
static DefaultFileCacheBacking.IndexEntry[] readIndex(java.io.File indexFile)
           
 void remove(CachedClassReference ref)
          Remove an entry from the cache
protected  long write(java.io.File file, byte[] bytes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEAVED_CLASS_CACHE_DIR

public static final java.lang.String WEAVED_CLASS_CACHE_DIR
See Also:
Constant Field Values

INDEX_FILE

public static final java.lang.String INDEX_FILE
See Also:
Constant Field Values
Constructor Detail

DefaultFileCacheBacking

protected DefaultFileCacheBacking(java.io.File cacheDirectory,
                                  CacheKeyResolver resolver)
Method Detail

createBacking

public static CacheBacking createBacking(java.io.File cacheDir,
                                         CacheKeyResolver resolver)

readIndex

public static DefaultFileCacheBacking.IndexEntry[] readIndex(java.io.File indexFile)

clear

public void clear()
Description copied from interface: CacheBacking
Clear the entire cache

Specified by:
clear in interface CacheBacking

createBacking

public static CacheBacking createBacking(java.lang.String scope,
                                         CacheKeyResolver resolver)

getKeys

public java.lang.String[] getKeys(java.lang.String regex)
Description copied from interface: CacheBacking
Return a list of keys which match the given regex.

Specified by:
getKeys in interface CacheBacking
Returns:

get

public CachedClassEntry get(CachedClassReference ref)
Description copied from interface: CacheBacking
Get a cache entry

Specified by:
get in interface CacheBacking
Parameters:
ref - entry to retrieve
Returns:
the cached bytes or null, if the entry does not exist

put

public void put(CachedClassEntry entry)
Description copied from interface: CacheBacking
Put an entry in the cache

Specified by:
put in interface CacheBacking
Parameters:
entry - key of the entry

remove

public void remove(CachedClassReference ref)
Description copied from interface: CacheBacking
Remove an entry from the cache

Specified by:
remove in interface CacheBacking

read

protected byte[] read(java.io.File file,
                      long expectedCRC)

write

protected long write(java.io.File file,
                     byte[] bytes)

delete

protected static void delete(java.io.File file)

close

protected static void close(java.io.OutputStream out,
                            java.io.File file)

close

protected static void close(java.io.InputStream in,
                            java.io.File file)