+

Search Tips   |   Advanced Search

Use the DistributedMap and DistributedObjectCache interfaces for the dynamic cache

By using the DistributedMap or DistributedObjectCache interfaces, Java EE applications and system components can cache and share Java objects by storing a reference to the object in the cache.

The DistributedMap and DistributedObjectCache interfaces are simple interfaces for the dynamic cache. Using these interfaces, Java EE applications and system components can cache and share Java objects by storing a reference to the object in the cache. The default dynamic cache instance is created if the dynamic cache service is enabled in the console. This default instance is bound to the global JNDI namespace using the name services/cache/distributedmap.

Multiple instances of the DistributedMap and DistributedObjectCache interfaces on the same JVM enable applications to separately configure cache instances as needed. Each instance of the DistributedMap interface has its own properties.

For more information see the API documentation for the com.ibm.websphere.cache package.

If we are using custom object keys, place the classes in a shared library. We can define the shared library at cell, node, or server level. Then, in each server create a class loader and associate it with the shared library definedd. See:

Place JAR files in a shared library when you deploy the application in a cluster with replication enabled. Simply turning on replication does not require a shared library; however, if you are using application-specific Java objects, such as cache key or cache value, those Java classes are required to be in the shared library. If those values are not in a shared library, you will get ClassNotFound exceptions when the DRS attempts to deserialize those objects on the receiving side.

In a clustered environment, the content you place in cache might be shared with other servers in the cluster. The content might also be offloaded to disk. If we intend to have the cached objects shared or offloaded to disk, you must make these particular objects serializable. If the objects you place in cache are non-serializable, specify that the sharing policy for these objects is not shared. The DistributedMap interface DistributedMap interface contains information about how to specify the sharing policy for a cached object. Specifying a sharing policy other than not shared for non-serializable objects can result in poor system performance. There are four methods for configuring and using cache instances:

The preceding example creates two cache instances named instance_one and instance_two. Cache instance_one has a cache entry size of 1,000 and instance_two has a cache entry size of 1,500. Disk offload is enabled in instance_one and disabled in instance_two. Use listener context is enabled in instance_one and disabled in instance_two. Flush to disk on stop is enabled in instance_one and disabled in instance_two. Cache replication is enabled in instance_two and disabled in instance_one. The name of the data replication domain for instance_two is DynaCacheCluster. Dependency ID support is disabled in instance_two.

Place the cacheinstances.properties file in either the application server or application class path. For example, we can use the application WAR file, WEB-INF\classes directory or server_root\classes directory. The first entry in the properties file (cache.instance.0) specifies the JNDI name for the cache instance in the global namespace.

We can use the following code to look up the cache instance:


Subtopics


Related concepts

Cache instances
  • Use the dynamic cache service
  • Configure dynamic cache disk offload
  • Use object cache instances
  • Java virtual machine cache settings