/** * Constructor for the PurgatoryElement<K, V> object * * @param cacheElement CacheElement */ public PurgatoryElement( ICacheElement<K, V> cacheElement ) { super(cacheElement.getCacheName(), cacheElement.getKey(), cacheElement.getVal(), cacheElement.getElementAttributes()); this.cacheElement = cacheElement; }
/** * @param attr * @see ICacheElement#setElementAttributes */ @Override public void setElementAttributes( IElementAttributes attr ) { cacheElement.setElementAttributes( attr ); }
/** * Dump the cache entries from first to list for debugging. */ @SuppressWarnings("unchecked") // No generics for public fields public void dumpCacheEntries() { log.debug( "dumpingCacheEntries" ); for ( MemoryElementDescriptor<K, V> me = list.getFirst(); me != null; me = (MemoryElementDescriptor<K, V>) me.next ) { log.debug( "dumpCacheEntries> key=" + me.ce.getKey() + ", val=" + me.ce.getVal() ); } }
/** * Log some details. * <p> * @param item */ private void logUpdateInfo( ICacheElement<K, V> item ) { if ( log.isInfoEnabled() ) { // not thread safe, but it doesn't have to be accurate puts++; if ( puts % logInterval == 0 ) { log.info( "puts = " + puts ); } } if ( log.isDebugEnabled() ) { log.debug( "In update, put [" + item.getKey() + "] in [" + item.getCacheName() + "]" ); } }
/** verify the check for removal * <p> * @throws IOException */ public void testCheckForRemoval_IdleTooLong() throws IOException { // SETUP CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes(); cacheAttr.setCacheName("testRegion"); cacheAttr.setMaxMemoryIdleTimeSeconds( 10 ); cacheAttr.setMaxSpoolPerRun( 10 ); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttr, new ElementAttributes()); String key = "key"; String value = "value"; ICacheElement<String, String> element = new CacheElement<String, String>( "testRegion", key, value ); ElementAttributes elementAttr = new ElementAttributes(); elementAttr.setIsEternal( false ); element.setElementAttributes( elementAttr ); element.getElementAttributes().setMaxLife(100); element.getElementAttributes().setIdleTime( 1 ); long now = System.currentTimeMillis(); // add two seconds now += 2000; // DO WORK boolean result = cache.isExpired( element, now, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND ); // VERIFY assertTrue( "Item should have expired.", result ); }
/** * @return cacheElement.getVal(); * @see ICacheElement#getVal */ @Override public V getVal() { return cacheElement.getVal(); }
if ( cacheElement.getKey() instanceof String && cacheElement.getKey().toString().endsWith( CacheConstants.NAME_COMPONENT_DELIMITER ) ) else if ( cacheElement.getKey() instanceof GroupId ) log.debug( "Updating memory cache " + cacheElement.getKey() ); cacheElement.getElementAttributes().setLastAccessTimeNow();
/** * @return cacheElement.getElementAttributes(); * @see ICacheElement#getElementAttributes */ @Override public IElementAttributes getElementAttributes() { return cacheElement.getElementAttributes(); }
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
/** * @return cacheElement.getKey(); * @see ICacheElement#getKey */ @Override public K getKey() { return cacheElement.getKey(); }
/** * * @throws Exception */ public void testSimpleElementRetrieval() throws Exception { CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" ); jcs.put( "test_key", "test_data" ); long now = System.currentTimeMillis(); ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" ); assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() ); long diff = now - elem.getElementAttributes().getCreateTime(); assertTrue( "Create time should have been at or after the call", diff >= 0 ); }
/** * @return cacheElement.getCacheName(); * @see ICacheElement#getCacheName */ @Override public String getCacheName() { return cacheElement.getCacheName(); }
/** verify the check for removal * <p> * @throws IOException */ public void testCheckForRemoval_IdleTooLong() throws IOException { // SETUP CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes(); cacheAttr.setCacheName("testRegion"); cacheAttr.setMaxMemoryIdleTimeSeconds( 10 ); cacheAttr.setMaxSpoolPerRun( 10 ); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttr, new ElementAttributes()); String key = "key"; String value = "value"; ICacheElement<String, String> element = new CacheElement<String, String>( "testRegion", key, value ); ElementAttributes elementAttr = new ElementAttributes(); elementAttr.setIsEternal( false ); element.setElementAttributes( elementAttr ); element.getElementAttributes().setMaxLife(100); element.getElementAttributes().setIdleTime( 1 ); long now = System.currentTimeMillis(); // add two seconds now += 2000; // DO WORK boolean result = cache.isExpired( element, now, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND ); // VERIFY assertTrue( "Item should have expired.", result ); }
/** * Log some details. * <p> * @param item */ private void logUpdateInfo( ICacheElement<K, V> item ) { // not thread safe, but it doesn't have to be 100% accurate puts++; if ( log.isInfoEnabled() ) { if ( puts % logInterval == 0 ) { log.info( "puts = " + puts ); } } if ( log.isDebugEnabled() ) { log.debug( "In update, put [" + item.getKey() + "] in [" + item.getCacheName() + "]" ); } }
/** * @return cacheElement.getVal(); * @see ICacheElement#getVal */ @Override public V getVal() { return cacheElement.getVal(); }
@Override protected void doExpires(final ICacheElement<A, B> element) { super.doExpires(element); for (final JCSListener<A, B> listener : listeners.values()) { listener.onExpired(Arrays.<CacheEntryEvent<? extends A, ? extends B>> asList(new JCSCacheEntryEvent<A, B>( cacheRef, EventType.REMOVED, null, element.getKey(), element.getVal()))); } }
if ( cacheElement.getKey() instanceof String && cacheElement.getKey().toString().endsWith( CacheConstants.NAME_COMPONENT_DELIMITER ) ) else if ( cacheElement.getKey() instanceof GroupId ) log.debug( "Updating memory cache " + cacheElement.getKey() ); cacheElement.getElementAttributes().setLastAccessTimeNow();
/** * @return cacheElement.getElementAttributes(); * @see ICacheElement#getElementAttributes */ @Override public IElementAttributes getElementAttributes() { return cacheElement.getElementAttributes(); }
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
/** * @return cacheElement.getKey(); * @see ICacheElement#getKey */ @Override public K getKey() { return cacheElement.getKey(); }