## org.springframework.core.type.classreading
Class CachingMetadataReaderFactory

    java.lang.Object
      org.springframework.core.type.classreading.SimpleMetadataReaderFactory
          org.springframework.core.type.classreading.CachingMetadataReaderFactory

All Implemented Interfaces:
  MetadataReaderFactory

    public class CachingMetadataReaderFactory

extends SimpleMetadataReaderFactory

Caching implementation of the `MetadataReaderFactory` interface, caching `MetadataReader` per Spring `Resource` handle (i.e. per ".class" file).

Since:
  2.5
Author:
  Juergen Hoeller, Costin Leau

Field Summary
`static int` `DEFAULT_CACHE_LIMIT` Default maximum number of entries for the MetadataReader cache: 256

Constructor Summary
`CachingMetadataReaderFactory()` Create a new CachingMetadataReaderFactory for the default class loader.
`CachingMetadataReaderFactory(ClassLoader classLoader)` Create a new CachingMetadataReaderFactory for the given class loader.
`CachingMetadataReaderFactory(ResourceLoader resourceLoader)` Create a new CachingMetadataReaderFactory for the given resource loader.

Method Summary
`int` `getCacheLimit()` Return the maximum number of entries for the MetadataReader cache.
`MetadataReader` `getMetadataReader(Resource resource)` Obtain a MetadataReader for the given resource.
`void` `setCacheLimit(int cacheLimit)` Specify the maximum number of entries for the MetadataReader cache.

Methods inherited from class org.springframework.core.type.classreading.SimpleMetadataReaderFactory
`getMetadataReader, getResourceLoader`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_CACHE_LIMIT

    public static final int DEFAULT_CACHE_LIMIT

  Default maximum number of entries for the MetadataReader cache: 256

  See Also:
    Constant Field Values

Constructor Detail

### CachingMetadataReaderFactory

    public CachingMetadataReaderFactory()

  Create a new CachingMetadataReaderFactory for the default class loader.

### CachingMetadataReaderFactory

    public CachingMetadataReaderFactory(ResourceLoader resourceLoader)

  Create a new CachingMetadataReaderFactory for the given resource loader.

  Parameters:
    `resourceLoader` - the Spring ResourceLoader to use (also determines the ClassLoader to use)

### CachingMetadataReaderFactory

    public CachingMetadataReaderFactory(ClassLoader classLoader)

  Create a new CachingMetadataReaderFactory for the given class loader.

  Parameters:
    `classLoader` - the ClassLoader to use

Method Detail

### setCacheLimit

    public void setCacheLimit(int cacheLimit)

  Specify the maximum number of entries for the MetadataReader cache. Default is 256.

### getCacheLimit

    public int getCacheLimit()

  Return the maximum number of entries for the MetadataReader cache.

### getMetadataReader

    public MetadataReader getMetadataReader(Resource resource)
                                     throws IOException

  Description copied from interface: `MetadataReaderFactory`
  Obtain a MetadataReader for the given resource.

  Specified by:
    `getMetadataReader` in interface `MetadataReaderFactory`
  Overrides:
    `getMetadataReader` in class `SimpleMetadataReaderFactory`
  Parameters:
    `resource` - the resource (pointing to a ".class" file)
  Returns:
    a holder for the ClassReader instance (never `null`)
  Throws:
    `IOException` - in case of I/O failure