@Test public void testRefresh() throws Exception { final String value = "value"; final CountingCacheEntryFactory factory = new CountingCacheEntryFactory(value); selfPopulatingCache = new SelfPopulatingCache(cache, factory); assertSame(value, selfPopulatingCache.get("key").getObjectValue()); assertEquals(1, factory.getCount()); selfPopulatingCache.refresh(); assertEquals(2, factory.getCount()); assertSame(value, selfPopulatingCache.get("key").getObjectValue()); assertEquals(2, factory.getCount()); }
public void refresh() throws CacheException { Exception exception = null; Object keyWithException = null; final Collection keys = getKeys(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": found " + keys.size() + " keys to refresh"); } for (Iterator iterator = keys.iterator(); iterator.hasNext();) { final Object key = iterator.next(); try { Ehcache backingCache = getCache(); final Element element = backingCache.getQuiet(key); if (element == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": entry with key " + key + " has been removed - skipping it"); } continue; } refreshElement(element, backingCache); } catch (final Exception e) { LOG.log(Level.WARNING, getName() + "Could not refresh element " + key, e); exception = e; } } if (exception != null) { throw new CacheException(exception.getMessage() + " on refresh with key " + keyWithException); } }
SelfPopulatingCache extends BlockingCache { public void refresh() throws CacheException { Exception exception = null; Object keyWithException = null; final Collection keys = getKeys(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": found " + keys.size() + " keys to refresh"); } for (Iterator iterator = keys.iterator(); iterator.hasNext();) { final Object key = iterator.next(); try { Ehcache backingCache = getCache(); final Element element = backingCache.getQuiet(key); if (element == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": entry with key " + key + " has been removed - skipping it"); } continue; } refreshElement(element, backingCache); } catch (final Exception e) { LOG.log(Level.WARNING, getName() + "Could not refresh element " + key, e); exception = e; } } if (exception != null) { throw new CacheException(exception.getMessage() + " on refresh with key " + keyWithException); } } }
SelfPopulatingCache extends BlockingCache { public void refresh() throws CacheException { Exception exception = null; Object keyWithException = null; final Collection keys = getKeys(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": found " + keys.size() + " keys to refresh"); } for (Iterator iterator = keys.iterator(); iterator.hasNext();) { final Object key = iterator.next(); try { Ehcache backingCache = getCache(); final Element element = backingCache.getQuiet(key); if (element == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": entry with key " + key + " has been removed - skipping it"); } continue; } refreshElement(element, backingCache); } catch (final Exception e) { LOG.log(Level.WARNING, getName() + "Could not refresh element " + key, e); exception = e; } } if (exception != null) { throw new CacheException(exception.getMessage() + " on refresh with key " + keyWithException); } } SelfPopulatingCache(final Ehcache cache, final CacheEntryFactory factory); }
SelfPopulatingCache extends BlockingCache { public void refresh() throws CacheException { Exception exception = null; Object keyWithException = null; final Collection keys = getKeys(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": found " + keys.size() + " keys to refresh"); } for (Iterator iterator = keys.iterator(); iterator.hasNext();) { final Object key = iterator.next(); try { Ehcache backingCache = getCache(); final Element element = backingCache.getQuiet(key); if (element == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": entry with key " + key + " has been removed - skipping it"); } continue; } refreshElement(element, backingCache); } catch (final Exception e) { LOG.log(Level.WARNING, getName() + "Could not refresh element " + key, e); exception = e; } } if (exception != null) { throw new CacheException(exception.getMessage() + " on refresh with key " + keyWithException); } } SelfPopulatingCache(final Ehcache cache, final CacheEntryFactory factory); Element get(final Object key); void refresh(); }
SelfPopulatingCache extends BlockingCache { public void refresh() throws CacheException { Exception exception = null; Object keyWithException = null; final Collection keys = getKeys(); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": found " + keys.size() + " keys to refresh"); } for (Iterator iterator = keys.iterator(); iterator.hasNext();) { final Object key = iterator.next(); try { Ehcache backingCache = getCache(); final Element element = backingCache.getQuiet(key); if (element == null) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest(getName() + ": entry with key " + key + " has been removed - skipping it"); } continue; } refreshElement(element, backingCache); } catch (final Exception e) { LOG.log(Level.WARNING, getName() + "Could not refresh element " + key, e); exception = e; } } if (exception != null) { throw new CacheException(exception.getMessage() + " on refresh with key " + keyWithException); } } SelfPopulatingCache(final Ehcache cache, final CacheEntryFactory factory); Element get(final Object key); void refresh();  }