NHBFighter
asked on
invalidate cache entries in Dynacache based on database entry
Hi experts
We are looking in to using websphere dynacache to cache a data structure that we build from the results of a db query. The data base tables are updated about every 5 minutes or so and we want to rerun the query and re-cache the data at about the same time the db is updated. A small table exists that stores the timestamp of the last time an update was made. What options are available to invalidate the cached data using this configuration?
We were thinking we could poll that table every 30 seconds or so and see if the time stamp has changed since the last time the data was cached. But I have not used dynacache before and from what I've read so far I don't know how to make it work the way we would like it to. Any suggestions?
Thanks
Dave
We are looking in to using websphere dynacache to cache a data structure that we build from the results of a db query. The data base tables are updated about every 5 minutes or so and we want to rerun the query and re-cache the data at about the same time the db is updated. A small table exists that stores the timestamp of the last time an update was made. What options are available to invalidate the cached data using this configuration?
We were thinking we could poll that table every 30 seconds or so and see if the time stamp has changed since the last time the data was cached. But I have not used dynacache before and from what I've read so far I don't know how to make it work the way we would like it to. Any suggestions?
Thanks
Dave
So you need to configure Cache Invalidation with your code.
You can check "WebSphere Application Server V6 Scalability and Performance Handbook" from http://www.redbooks.ibm.com
Following is
The dynamic cache service provides event-based and time-based invalidation
techniques. WebSphere Application Server V6 offers access to programmatic
cache and invalidation techniques. Invalidation policies can be defined with XML
cache policy files. Invalidation policies allow triggering events to invalidate cache
entries without the need to write explicit code. More complex invalidation
scenarios may require code, which invokes the invalidation API.
Below Example shows the invalidation policy, which invalidates cache entries for
groups of objects using the same Account_UserID dependency ID. For example,
home servlet and all commands invoked by home servlet are invalidated when
the user logs out from the application.
Following Example show Invalidation policy defined in the logout command in cachespec.xml file
( please refer to the WebSphere InfoCenter for more detailed information about the cachespec.xml file. )
<cache-entry>
<class>command</class>
<sharing-policy>not-shared </sharing- policy>
<name>com.ibm.websphere.sa mples.trad e.command. LogoutComm and</name>
<invalidation>Account_User ID
<component id="getUserID" type="method">
<required>true</required>
</component>
</invalidation>
<invalidation>Holdings_Use rID1
<component id="getUserID" type="method">
<required>true</required>
</component>
</invalidation>
</cache-entry>
Cheers
Andy
You can check "WebSphere Application Server V6 Scalability and Performance Handbook" from http://www.redbooks.ibm.com
Following is
The dynamic cache service provides event-based and time-based invalidation
techniques. WebSphere Application Server V6 offers access to programmatic
cache and invalidation techniques. Invalidation policies can be defined with XML
cache policy files. Invalidation policies allow triggering events to invalidate cache
entries without the need to write explicit code. More complex invalidation
scenarios may require code, which invokes the invalidation API.
Below Example shows the invalidation policy, which invalidates cache entries for
groups of objects using the same Account_UserID dependency ID. For example,
home servlet and all commands invoked by home servlet are invalidated when
the user logs out from the application.
Following Example show Invalidation policy defined in the logout command in cachespec.xml file
( please refer to the WebSphere InfoCenter for more detailed information about the cachespec.xml file. )
<cache-entry>
<class>command</class>
<sharing-policy>not-shared
<name>com.ibm.websphere.sa
<invalidation>Account_User
<component id="getUserID" type="method">
<required>true</required>
</component>
</invalidation>
<invalidation>Holdings_Use
<component id="getUserID" type="method">
<required>true</required>
</component>
</invalidation>
</cache-entry>
Cheers
Andy
ASKER
I think I understand that but for these to work something has to be triggered correct. IE a method in the command has to be called. What I need is to have something wake up every 30 seconds or so, see if the cache should be invalidated and then trigger the mehtod to invalidate the cache.
The idea we are working on now is to have two things in cache one is the data we want to cache and the other is a dummy object. The dummy object will be put into the cache and its TTL will be set to 30 seconds. Then we will put a listner on the experiation of that dummy object. When the listener is triggered the data base can be polled to see if the cache has expired. If so the update to the data we want to cache can be made. This process of the dummy object expiring every 30 seconds will be repeated indefinetly.
How does that idea sound?
Thanks
Dave
The idea we are working on now is to have two things in cache one is the data we want to cache and the other is a dummy object. The dummy object will be put into the cache and its TTL will be set to 30 seconds. Then we will put a listner on the experiation of that dummy object. When the listener is triggered the data base can be polled to see if the cache has expired. If so the update to the data we want to cache can be made. This process of the dummy object expiring every 30 seconds will be repeated indefinetly.
How does that idea sound?
Thanks
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER