Skip Headers

# Guidelines for Configuring the Cache and Identity Maps

Previous

Next

You can configure the cache at the project ("Configuring Cache Type and Size at the Project Level") or descriptor ("Configuring Cache Type and Size at the Descriptor Level") level.

Use the following guidelines when configuring your cache and identity map:

- If objects with a long life span and object identity are important, use a `SoftCacheWeakIdentityMap` or `HardCacheWeakIdentityMap` policy. For more information on when to choose one or the other, see "Understanding the Internals of Soft and Hard Cache Weak Identity Map".

- If object identity is important, but caching is not, use a `WeakIdentityMap` policy.

- If an object has a long life span or requires frequent access, or object identity is important, use a `FullIdentityMap` policy.

  WARNING: Use the `FullIdentityMap` only if the class has a small number of finite instances. Otherwise, a memory leak will occur.

- If an object has a short life span or requires frequent access, and identity is not important, use a `CacheIdentityMap` policy.

- If objects are discarded immediately after being read from the database, such as in a batch operation, use a `NoIdentityMap` policy. The `NoIdentityMap` does not preserve object identity.

Note: Oracle does not recommend the use of `CacheIdentityMap` and `NoIdentityMap` policies.