/** * Clear the cache for a given cacheKey. * * @param cacheKey * key as defined by {@link HystrixCommand#getCacheKey()} */ public void Clear(String cacheKey) { ValueCacheKey key = GetRequestCacheKey(cacheKey); if (key != null) { /* remove this cache key */ object future; requestVariableForCache.Get(concurrencyStrategy).TryRemove(key, out future); } }
/** * Retrieve a cached Future for this request scope if a matching command has already been executed/queued. * * @return {@code Future<T>} */ // suppressing warnings because we are using a raw Future since it's in a heterogeneous ConcurrentHashMap cache public IFuture <T> Get <T>(string cacheKey) { ValueCacheKey key = GetRequestCacheKey(cacheKey); if (key != null) { /* look for the stored value */ object result = null; requestVariableForCache.Get(concurrencyStrategy).TryGetValue(key, out result); return((IFuture <T>)result); } return(null); }
/** * Put the Future in the cache if it does not already exist. * <p> * If this method returns a non-null value then another thread won the race and it should be returned instead of proceeding with execution of the new Future. * * @param cacheKey * key as defined by {@link HystrixCommand#getCacheKey()} * @param f * Future to be cached * * @return null if nothing else was in the cache (or this {@link HystrixCommand} does not have a cacheKey) or previous value if another thread beat us to adding to the cache */ // suppressing warnings because we are using a raw Future since it's in a heterogeneous ConcurrentHashMap cache public IFuture <T> PutIfAbsent <T>(string cacheKey, IFuture <T> f) { ValueCacheKey key = GetRequestCacheKey(cacheKey); if (key != null) { IFuture <T> set = (IFuture <T>)requestVariableForCache.Get(concurrencyStrategy).GetOrAdd(key, f); if (set == f) // we win, this means the previos value was null { return(null); } else { return(set); } } // we either set it in the cache or do not have a cache key return(null); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } ValueCacheKey other = (ValueCacheKey)obj; if (rvKey == null) { if (other.rvKey != null) { return(false); } } else if (!rvKey.Equals(other.rvKey)) { return(false); } if (valueCacheKey == null) { if (other.valueCacheKey != null) { return(false); } } else if (!valueCacheKey.Equals(other.valueCacheKey)) { return(false); } return(true); }