Data expiration using Omnifaces <o: cache>
I have a large buffer of application content that I want to keep in memory. Using Omnifaces makes this pretty easy.
However, if I need to expire the cache, there seems to be no way to do this. I can set the time attribute if necessary, but this is actually not an ideal answer to this riddle.
Any suggestions on pushing baseline updates?
Thanks,
Temar
However, if I need to finish the cache, there is no method for this.
There really is no method in the tag / component, but there is a programmatic path. This works best if you have assigned an explicit key to write to the cache:
<o:cache key="myCache"> cached content here </o:cache> Then in the background bean you can delete the contents for this entry as follows:
public void reset() { CacheFactory.getCache(Faces.getContext(), "session").remove("myCache"); } Note that the default scope is βsession,β so it is used here. If you used a different scope for the tag (for example, "application"), you must specify this in your bean code.
You can call this method whenever you know that the cache must have expired (for example, if the action method has updated some backup data) or you can make an explicit reset button:
<h:form> <h:commandButton action="#{someBean.reset}" value="Reset cache" /> </h:form> For OmniFaces 1.5, we plan to add an attribute to the o:cache tag to make it simpler, and we will add an example to our storefront showing how to expire entries manually.