Exemplo n.º 1
0
        public void Clear(string cacheKey)
        {
            ValueCacheKey key = GetRequestCacheKey(cacheKey);

            if (key != null)
            {
                /* remove this cache key */
                var cacheInstance = RequestVariableForCache.Value;
                cacheInstance.TryRemove(key, out object removed);
            }
        }
Exemplo n.º 2
0
        public T Get <T>(string cacheKey)
        {
            ValueCacheKey key    = GetRequestCacheKey(cacheKey);
            object        result = null;

            if (key != null)
            {
                var cacheInstance = requestVariableForCache.Value;
                /* look for the stored value */
                if (cacheInstance.TryGetValue(key, out result))
                {
                    return((T)result);
                }
            }
            return(default(T));
        }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
0
        internal T PutIfAbsent <T>(string cacheKey, T f)
        {
            ValueCacheKey key    = GetRequestCacheKey(cacheKey);
            object        result = null;

            if (key != null)
            {
                var cacheInstance = requestVariableForCache.Value;
                result = cacheInstance.GetOrAdd(key, f);
                if (f.Equals(result))
                {
                    return(default(T));
                }
                else
                {
                    return((T)result);
                }
            }
            return(default(T));
        }
Exemplo n.º 5
0
 public CacheKey Key(string id) {
     var key = new ValueCacheKey(this, id);
     _dKeys[id] = key;
     return key;
 }