Updating selfpopulatingcache example Chatfisting

Posted by / 09-Dec-2017 03:24

In this part of the article about caching we’ll discuss using Eh Cache for a different purpose other than as Hibernate second level cache.

Before working with Eh Cahe, I used a static variable for a cache.

I use EHCache to maintain a mostly read-only cache of results from database queries. However, there is one table which needs an odd access method that is causing me grief.

To achieve this I use a method that always checks to see if the cache has expired and if it has, rebuilds it.

The pattern delegates SOR reading and writing activies to the cache, so that application code is absolved of this responsibility.

To implement the cache-as-sor pattern, use a combination of the following read and write patterns: .

Since it would be an Eh Cache type of cache, it would have the properties of the cache configured in the file, and we are especially interested in the expiration property if we want to refresh this cache at some interval.

The cache knows how to populate itself, after expiration it would again use the method to retrieve the new values, so the second problem of expiration would be solved.

updating selfpopulatingcache example-35updating selfpopulatingcache example-54updating selfpopulatingcache example-52

It also supports use with the popular Hibernate Object/Relational tool and caching with the Java EE Servlet. The rest of the documentation can be explored for a deeper understanding. This means that application code which accesses the system-of-record (SOR) should consult the cache first, and if the cache contains the data, then return the data directly from the cache, bypassing the SOR.

One thought on “updating selfpopulatingcache example”