Menu

Realtime detection of expired elements

2007-01-02
2013-05-14
  • mjohnsonaz74

    mjohnsonaz74 - 2007-01-02

    Let me outline what I'm trying to accomplish rather than ask an ambiguous question.  I have a cache of several thousand documents that users can look through.  Documents may be updated, so to detect updates or new documents I set the cache elements to expire after 30 minutes.  The problem is, when a user requests a page with expired elements, it takes the page about 8 seconds to load.  Naturally, when the documents are cached, the page loads quite quickly.  I'd like to eliminate this long wait.  Is there any way to detect that elements have expired in realtime and automatically ping the URL to re-cache my documents?  I looked at the CacheEventListener, but it only triggers when a user makes a get request to the cache.  I need to be able to register a listener that polls the cache and tells me when an element is expired.  I want to make sure that the cache is current for all users, not just the ones who follow the unlucky soul who hits an expired cache.  Any thoughts or recomendations would be appreciated.  I'm sure there is another solution, but I've been looking at this for too long and I think my brain is locking up.  Thank you!

     
    • Steven

      Steven - 2007-05-15

      Your design assumes document change.  Your solution is to have cached elements expire whether or not the document has changed or not.  This is probably not the best approach.  Don't set the elements to expire.  Instead, set them to live forever and have an external process update the elements.  The external process can be either be notified of changes to the documents or it can be a scheduled (quartz?) process and then update the cached document accordingly. 

      This approach means that users should never see the 8 second update time for a document.  That all happens outside of the cache.  Putting the new document into the cache with the same key name replaces the cached element atomically (I think) so users never see an expired element.

       
    • bh25

      bh25 - 2009-07-15

      I would recommend using a SelfPopulatingCache and calling refresh() on it periodically.

      Additional benefits of this approach include, per docs on SelfPopulatingCache.refresh():

      Refreshes bypass the BlockingCache and act directly on the backing Ehcache. This way, BlockingCache gets can continue to return stale data while the refresh, which might be expensive, takes place.

       

Log in to post a comment.