Back to JOC 10.1.2 Tutorial Index

Batch Loading and Invalidation

As described in Automatic Loading, CacheAccess.get() can be used to automatically load one object into the cache. With the Cache Service method CacheAccess.loadList(), you can load an entire array of objects into the cache at a time.

The loadList method passes the names of all unloaded objects in a given list (array) to a CacheListLoader class associated with the objects. If there is no CacheListLoader for an object or if different objects in the list have different CacheListLoader, the objects will be loaded individually. All objects will be stored in the cache as individual objects. All exceptions will be logged, but only the last exception will be thrown. A CacheListLoader can only be associated with a region or a group.

The example below demonstrates how to use the loadList method.

import oracle.ias.cache.*;

  CacheAccess     cacc;
  String          list[];
  int             listCnt = 12;
  String          region  = "region";
  String          name    = "object ";
  MyListLoader    loader  = new MyListLoader();
  CacheAttributes cAttr   = new CacheAttributes();
  Attributes      attr    = new Attributes();

  Cache.init(cAttr);
  attr.setLoader(loader); // set the loader for the region
  CacheAccess.defineRegion(region, attr);
  cacc = CacheAccess.getAccess(region);

  // initialize the object name list
  list = new String[listCnt];

  for (int i = 0; i < listCnt; i++)
    list[i] = name + i;

  // load list
  cacc.loadList(list);
The CacheListLoader class is a subclass of the CacheLoader class. In addition to implementing the load method, you will also have to implement the loadList method for loading multiple objects. The CacheListLoader class provides several protected methods to help you implement loadList. getList provides the original list passed into CacheAccess.loadList(). getNextObject returns the name of the next object in the list to be loaded and sets the context so that a subsequent call to saveObject will load into the cache the current object that needs to be loaded. Optionally, saveObject can also directly load a named object into the cache without depending on any other context. getNamedObject sets the context such that a subsequent call to saveObject will load into the cache the named object.

The example below demonstrates a loader that loads every other object in the list.

import oracle.ias.cache.*;

class HalfListLoader extends CacheListLoader
{

  public void loadList(Object handle, Object args) throws CacheException
  {

    Object list[] = getList(handle);

    for (int i = 0; i < list.length; i++)
    {

      if ((i % 2) == 0)
      {

        getNamedObject(handle, list[i]);
        saveObject(handle, getName(handle));

      }

    }

  }

  public Object load(Object handle, Object args) throws CacheException
  {

    return null;

  }
In addition, the Cache and CacheAccess methods invalidate and destroy have been overloaded to invalidate/destroy an array of objects at a time. Batch loading and invalidation replaces potentially many similar cache calls with a single cache call, thus improving communication efficiency with/in the cache.

Back to JOC 10.1.2 Tutorial Index

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy