Reputation: 317
I have a large buffer of application scoped content that I want to keep in memory. Using Omnifaces let's do that pretty easily.
However, if I need to expire the cache, there appears to be no method to do so. I can set the time attribute if needed, but that doesn't really seem to be the ideal answer to this puzzle.
Any suggestions for forcing to update the underlying data?
Thanks,
Temar
Upvotes: 4
Views: 245
Reputation: 38163
However, if I need to expire the cache, there appears to be no method to do so.
On the tag/component there isn't a method indeed, but there is a programmatic way. This works best if you assign an explicit key to your cache entry:
<o:cache key="myCache">
cached content here
</o:cache>
Then in a backing bean you can remove content for that entry as follows:
public void reset() {
CacheFactory.getCache(Faces.getContext(), "session").remove("myCache");
}
Note that the default scope is "session", so that's used here. If you used another scope for the tag (like "application") you would specify that in your backing bean code.
You can call this method whenever you know that the cache needs to be expired (for instance, if an action method updated some backing 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've planned to add an attribute to the o:cache
tag to make this a bit more straightforward and we'll add an example to our showcase showing how to expire entries manually.
Upvotes: 5