So friends, If you have custom object and you want to share that object across any portlet application deployed on your portal environment,
DynaCache is the place where you can store your object and get the object where ever required back from DynaCache.
DynaCache Scenarios
scenarios i have worked with was
In my custom login portlet, i was required to store custom object at the time lo login and the same object should be available to all portlet applications deployed on portal.
For this, In my login portlet i stored the object into DynaCache and get the object from DynaCache where ever required.
There could be other scenarios as well, where you want to Cache data in JSR 168 portlets, Share information between IBM portlets and JSR 168 portlets
Technically, WebSphere Application Server provides the DistributedMap interface as a simple interface for the dynacache.
DynaCache implementation
First, you need to enable global dynacache service in the WebSphere Application Server administrative console.
By default, this service is enabled but in case if it's disabled, follow the steps below to enable it
1. Open the administrative console.
2. Select Servers => Application Servers in the administrative console navigation tree.
3. Click the WebSphere Portal server.
4. Select Additional Properties => Dynamic Cache Service.
5. In the Startup state field, select Enable service at server startup.
6. Click Apply or OK.
7. Restart WebSphere Application Server and WebSphere Portal Server.
Registering and configuring a new dynacache
Next, you need to register and configure a new dynacache instance for use by the portlet service
1. Open the administrative console.
2. Select Resources => Cache instance = > Object cache instances.
3. click New.
4. provide values to mandatory fields.
(I am giving JNDI values as services/cache/MyCustomObjectCache )
5. Click Ok and then Save.
Accessing/lookup of DynaCache service
Next, we will access/lookup DyanaCache Service. In portlets, where ever you are storing or getting the object to/from dyanacahe, you will have to lookup the service first and then you can store or get the object to/from dynacache.
Best paractice would be to lookup this service at the time of initialization.(init method of portlet)
//declare a class level variable
private DistributedMap distributedDynaCacheMap = null;
public void init(PortletConfig portletConfig) throws PortletException {
super.init(portletConfig);
Context context;
try {
context = new InitialContext();
distributedDynaCacheMap = (DistributedMap)context.lookup("services/cache/MyCustomObjectCache");
} catch (NamingException e) {
throw new PortletException();
}
Now, you have got your dynacache service lookedup...
To store object into dynacahe, simply call put method.
distributedDynaCacheMap.put(Object arg0, Object arg1);
To get object from dynacache in any of portlet, first you need to access/lookup the service and just call get method on distributedDynaCacheMap.
distributedDynaCacheMap.get(object argo);
Nice idea,keep sharing your ideas with us.i hope this information's will be helpful for the new learners.
ReplyDeletePython Training in Chennai
Python Classes in Chennai
JAVA Training in Chennai
Hadoop Training in Chennai
Selenium Training in Chennai
Python Training in Chennai
Python Course in Chennai
I was really satisfied to discover this page. I needed to thank you for ones time for this awesome read!! I certainly preferred all of it and I have you saved to fav to see new data in your blog.
ReplyDeletebest interiors