|Internal Discussion Link:||/|
I'm prototyping a little widget that scrapes Tickets from the Rational's web-based Clear Quest product and surfaces them in Jive. It's working fine, but it takes several seconds to scrape and render the data. One solution to improve rendering time is to implement a TTL cache for this data. So, I'm wondering if there is a already some pattern available to developers for caching the rendered widget html?
One could conceivably cache the data in the object instance or in some class instance, soft referenced map (assuming you can retrieve some unique id for that widget spot). However, the details would depend upon the lifecycle of a widget object. Is the widget lifecycle documented somewhere?
Unfortunately, we do not currently have any documentation detailed enough to show the lifecycle of a widget but from what I gather it is quite short. In most cases I believe it is over once the page is rendered. However, if you writing your own widget you might be able to create your own manager and cache to store and retrieve your data.
An example of a plugin which creates and utilizes it's own cache is the PhotoShare plugin, you can find the source here:
I should note, this code might not be up to date and might not work perfectly but hopefully it will be able to give you a good start. Thanks!
Also, if you have a source build, you can / should check out the com.jivesoftware.community.widget.impl.RssSubscriptionWidget class, which maintains it's own cache of rendered RSS feeds.