Configuring Object Cache

By default you can store your application specific objects in the default instance provided by the WAS. But if you want more control about say what level those objects should be store or how those objects should get flushed to disk then you can configure a custom Object instance from WAS Admin Console like this



As you can see i configured it so that if there are more than 2000 entries in the distributedMap those entries would get off loaded to the disk in c:/temp/objects directory. I wanted to try that so i created a DynaObjectServlet like this

public class DynamicObjectServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public DynamicObjectServlet() {
super();
// TODO Auto-generated constructor stub
}

private DistributedMap distributeMap;
public void init() throws ServletException {
super.init();
try {
Context ctx = new InitialContext();
System.out.println("Before getting the distributedMap");
distributeMap =(DistributedMap) ctx.lookup("services/cache/object_instance");
System.out.println("After getting the distributedMap " + distributeMap);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
System.out.println("Inside DynamicObjectServlet.doGet()");
for( int i = 0 ; i < 3000 ; i++){
System.out.println("Putting objects in distributedMap");
distributeMap.put("testObject"+i, "testValue");
}
System.out.println("DistributeMap " + distributeMap.get("testObject"));
response.getWriter().println("After storing object in distribute Map");
}

}


I have a big loop in the doGet() method that stores 3000 objects in the distributed map, where as the limit is 2000 so some of the objects will get pushed to disk. I tried hitting the DynaObjectServlet and then i checked the disk which is configured to act as offload location for the dynacache, i saw these files being created there



I tried opening the files but the content is stored in non text format there were funny characters in there.

No comments: