/** * Do not try to go remote or laterally for this get. * <p> * @param key * @return ICacheElement */ public ICacheElement<K, V> localGet( K key ) { return get( key, true ); }
JCSAdminBean admin = new JCSAdminBean(); LinkedList linkedList = admin.buildCacheInfo(); ListIterator iterator = linkedList.listIterator(); while (iterator.hasNext()) { CacheRegionInfo info = (CacheRegionInfo)iterator.next(); CompositeCache compCache = info.getCache(); System.out.println("Cache Name: " + compCache.getCacheName()); System.out.println("Cache Type: " + compCache.getCacheType()); System.out.println("Cache Misses (not found): " + compCache.getMissCountNotFound()); System.out.println("Cache Misses (expired): " + compCache.getMissCountExpired()); System.out.println("Cache Hits (memory): " + compCache.getHitCountRam()); System.out.println("Cache value: " + compCache.get(propId));
/** * Do not try to go remote or laterally for this get. * <p> * @param key * @return ICacheElement */ public ICacheElement<K, V> localGet( K key ) { return get( key, true ); }
/** * Gets an item from the cache. * <p> * @param key * @return element from the cache, or null if not present * @see org.apache.commons.jcs.engine.behavior.ICache#get(Object) */ @Override public ICacheElement<K, V> get( K key ) { return get( key, false ); }
/** * Gets an item from the cache. * <p> * @param key * @return element from the cache, or null if not present * @see org.apache.commons.jcs.engine.behavior.ICache#get(Object) */ @Override public ICacheElement<K, V> get( K key ) { return get( key, false ); }
/** * This method returns the ICacheElement<K, V> wrapper which provides access to element info and other * attributes. * <p> * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No * defensive copy is made. * <p> * This method is most useful if you want to determine things such as the how long the element * has been in the cache. * <p> * The last access time in the ElementAttributes should be current. * <p> * @param name Key the Serializable is stored as * @return The ICacheElement<K, V> if the object is found or null */ @Override public ICacheElement<K, V> getCacheElement( K name ) { return this.getCacheControl().get( name ); }
/** * This method returns the ICacheElement<K, V> wrapper which provides access to element info and other * attributes. * <p> * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No * defensive copy is made. * <p> * This method is most useful if you want to determine things such as the how long the element * has been in the cache. * <p> * The last access time in the ElementAttributes should be current. * <p> * @param name Key the Serializable is stored as * @return The ICacheElement<K, V> if the object is found or null */ @Override public ICacheElement<K, V> getCacheElement( K name ) { return this.getCacheControl().get( name ); }
/** * 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 public boolean containsKey(final K key) { assertNotClosed(); assertNotNull(key, "key"); return delegate.get(key) != null; }
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()))); } }
/** * Gets the elementAttributes attribute of the Cache object. * <p> * @param key * @return The elementAttributes value * @throws CacheException * @throws IOException */ public IElementAttributes getElementAttributes( K key ) throws CacheException, IOException { ICacheElement<K, V> ce = get( key ); if ( ce == null ) { throw new ObjectNotFoundException( "key " + key + " is not found" ); } return ce.getElementAttributes(); }
/** * Gets the elementAttributes attribute of the Cache object. * <p> * @param key * @return The elementAttributes value * @throws CacheException * @throws IOException */ public IElementAttributes getElementAttributes( K key ) throws CacheException, IOException { ICacheElement<K, V> ce = get( key ); if ( ce == null ) { throw new ObjectNotFoundException( "key " + key + " is not found" ); } return ce.getElementAttributes(); }
/** * 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; }
/** * Place a new object in the cache, associated with key name. If there is currently an object * associated with name in the region an ObjectExistsException is thrown. Names are scoped to a * region so they must be unique within the region they are placed. * <p> * @param key Key object will be stored with * @param value Object to store * @throws CacheException and ObjectExistsException is thrown if the item is already in the * cache. */ @Override public void putSafe( K key, V value ) { if ( this.getCacheControl().get( key ) != null ) { throw new ObjectExistsException( "putSafe failed. Object exists in the cache for key [" + key + "]. Remove first or use a non-safe put to override the value." ); } put( key, value ); }
public void putSafe(String key, Object object) { GroupAttrName<String> groupKey = getGroupAttrName(DEFAULT_GROUP_NAME, key); if (groupCacheAccess.getCacheControl().get(groupKey) != null) { throw new CacheException( "putSafe failed. Object exists in the cache for key [" + groupKey + "]. Remove first or use a non-safe put to override the value."); } put(key, object); }
/** * Place a new object in the cache, associated with key name. If there is currently an object * associated with name in the region an ObjectExistsException is thrown. Names are scoped to a * region so they must be unique within the region they are placed. * <p> * @param key Key object will be stored with * @param value Object to store * @throws CacheException and ObjectExistsException is thrown if the item is already in the * cache. */ @Override public void putSafe( K key, V value ) { if ( this.getCacheControl().get( key ) != null ) { throw new ObjectExistsException( "putSafe failed. Object exists in the cache for key [" + key + "]. Remove first or use a non-safe put to override the value." ); } put( key, value ); }
/** * Processes a get request. * <p> * If isAllowClusterGet is enabled we will treat this as a normal request or non-remote origins. * <p> * @param cacheName * @param key * @param requesterId * @return ICacheElement * @throws IOException */ @Override public ICacheElement<K, V> processGet( String cacheName, K key, long requesterId ) throws IOException { CompositeCache<K, V> cache = getCacheManager().getCache( cacheName ); boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet(); if ( keepLocal ) { return cache.localGet( key ); } else { return cache.get( key ); } }
/** * 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 ); }