/** * @return cacheElement.getVal(); * @see ICacheElement#getVal */ @Override public V getVal() { return cacheElement.getVal(); }
/** * @return cacheElement.getVal(); * @see ICacheElement#getVal */ @Override public V getVal() { return cacheElement.getVal(); }
/** * Dump the cache map for debugging. */ public void dumpMap() { log.debug( "dumpingMap" ); for (Map.Entry<K, MemoryElementDescriptor<K, V>> e : map.entrySet()) { MemoryElementDescriptor<K, V> me = e.getValue(); log.debug( "dumpMap> key=" + e.getKey() + ", val=" + me.ce.getVal() ); } }
/** * Dump the cache map for debugging. */ public void dumpMap() { log.debug( "dumpingMap" ); for (Map.Entry<K, MemoryElementDescriptor<K, V>> e : map.entrySet()) { MemoryElementDescriptor<K, V> me = e.getValue(); log.debug( "dumpMap> key=" + e.getKey() + ", val=" + me.getCacheElement().getVal() ); } }
/** * 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() ); } }
/** * Retrieve an object from the cache region this instance provides access to. * <p> * @param name Key the object is stored as * @return The object if found or null */ @Override public V get( K name ) { ICacheElement<K, V> element = this.getCacheControl().get( name ); return ( element != null ) ? element.getVal() : null; }
/** * Retrieve an object from the cache region this instance provides access to. * <p> * @param name Key the object is stored as * @return The object if found or null */ @Override public V get( K name ) { ICacheElement<K, V> element = this.getCacheControl().get( name ); return ( element != null ) ? element.getVal() : null; }
@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()))); } }
private void forceExpires(final K cacheKey) { final ICacheElement<K, V> elt = delegate.get(cacheKey); delegate.remove(cacheKey); for (final JCSListener<K, V> listener : listeners.values()) { listener.onExpired(Arrays.<CacheEntryEvent<? extends K, ? extends V>> asList(new JCSCacheEntryEvent<K, V>(this, EventType.REMOVED, null, cacheKey, elt.getVal()))); } }
private void expires(final K cacheKey) { final ICacheElement<K, V> elt = delegate.get(cacheKey); delegate.remove(cacheKey); for (final JCSListener<K, V> listener : listeners.values()) { listener.onExpired(Arrays.<CacheEntryEvent<? extends K, ? extends V>> asList(new JCSCacheEntryEvent<K, V>(this, EventType.REMOVED, null, cacheKey, elt.getVal()))); } }
/** * Dump the cache entries from first to list for debugging. */ @SuppressWarnings("unchecked") // No generics for public fields private 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.getCacheElement().getKey() + ", val=" + me.getCacheElement().getVal()); } }
/** * 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; }
/** * Constructor for the PurgatoryElement<K, V> object * <p> * @param cacheElement CacheElement */ public PurgatoryElement( ICacheElement<K, V> cacheElement ) { super(cacheElement.getCacheName(), cacheElement.getKey(), cacheElement.getVal(), cacheElement.getElementAttributes()); this.cacheElement = cacheElement; }
/** * Gets an item out of the cache that is in a specified group. * <p> * @param name * The key name. * @param group * The group name. * @return The cached value, null if not found. */ @Override public V getFromGroup( K name, String group ) { ICacheElement<GroupAttrName<K>, V> element = this.getCacheControl().get( getGroupAttrName( group, name ) ); return ( element != null ) ? element.getVal() : null; }
/** * Gets an item out of the cache that is in a specified group. * <p> * @param name * The key name. * @param group * The group name. * @return The cached value, null if not found. */ @Override public V getFromGroup( K name, String group ) { ICacheElement<GroupAttrName<K>, V> element = this.getCacheControl().get( getGroupAttrName( group, name ) ); return ( element != null ) ? element.getVal() : null; }
/** * Reset attributes for a particular element in the cache. NOTE: this method is currently not * implemented. * <p> * @param name Key of object to reset attributes for * @param attr New attributes for the object * @throws InvalidHandleException if the item does not exist. */ @Override public void resetElementAttributes( K name, IElementAttributes attr ) { ICacheElement<K, V> element = this.getCacheControl().get( name ); if ( element == null ) { throw new InvalidHandleException( "Object for name [" + name + "] is not in the cache" ); } // Although it will work currently, don't assume pass by reference here, // i.e. don't do this: // element.setElementAttributes( attr ); // Another reason to call put is to force the changes to be distributed. put( element.getKey(), element.getVal(), attr ); }
/** * Reset attributes for a particular element in the cache. NOTE: this method is currently not * implemented. * <p> * @param name Key of object to reset attributes for * @param attr New attributes for the object * @throws InvalidHandleException if the item does not exist. */ @Override public void resetElementAttributes( K name, IElementAttributes attr ) { ICacheElement<K, V> element = this.getCacheControl().get( name ); if ( element == null ) { throw new InvalidHandleException( "Object for name [" + name + "] is not in the cache" ); } // Although it will work currently, don't assume pass by reference here, // i.e. don't do this: // element.setElementAttributes( attr ); // Another reason to call put is to force the changes to be distributed. put( element.getKey(), element.getVal(), attr ); }
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); } } }
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); } } }
public void testAppendToDisk() throws Exception { String cacheName = "testAppendToDisk"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMaxKeySize(100); cattr.setBlockSizeBytes(500); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, X> diskCache = new BlockDiskCache<String, X>(cattr); diskCache.removeAll(); X value1 = new X(); value1.string = "1234567890"; X value2 = new X(); value2.string = "0987654321"; diskCache.update(new CacheElement<String, X>(cacheName, "1", value1)); diskCache.dispose(); diskCache = new BlockDiskCache<String, X>(cattr); diskCache.update(new CacheElement<String, X>(cacheName, "2", value2)); diskCache.dispose(); diskCache = new BlockDiskCache<String, X>(cattr); assertTrue(diskCache.verifyDisk()); assertEquals(2, diskCache.getKeySet().size()); assertEquals(value1.string, diskCache.get("1").getVal().string); assertEquals(value2.string, diskCache.get("2").getVal().string); }