예제 #1
0
        /// <summary>
        /// -99 = null input
        /// -1 = wrong type
        /// 0 = same type, wrong id
        /// 1 = same reference (same id, same type)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(ICacheKey other)
        {
            if (other != null)
            {
                try
                {
                    if (other.GetType() != GetType())
                    {
                        return(-1);
                    }

                    if (other.KeyHash().Equals(KeyHash()))
                    {
                        return(1);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(-99);
        }
예제 #2
0
        /// <summary>
        /// Adds an object to the cache
        /// </summary>
        /// <param name="objectToCache">the object to cache</param>
        /// <param name="cacheKey">the key to cache it under</param>
        public void Add(object objectToCache, ICacheKey cacheKey)
        {
            if (Exists(cacheKey))
            {
                Remove(cacheKey);
            }

            _globalCache.AddOrGetExisting(cacheKey.KeyHash(), objectToCache, _globalPolicy);
        }
예제 #3
0
        /// <summary>
        /// Adds an object to the cache
        /// </summary>
        /// <param name="objectToCache">the object to cache</param>
        /// <param name="cacheKey">the key to cache it under</param>
        public virtual void Add <T>(object objectToCache, ICacheKey cacheKey)
        {
            if (Exists(cacheKey))
            {
                Remove <T>(cacheKey);
            }

            AddKey(cacheKey.ValueType, cacheKey);

            _globalCache.Set(cacheKey.KeyHash(), objectToCache);
        }
예제 #4
0
        /// <summary>
        /// Gets one entity from the cache by its key
        /// </summary>
        /// <typeparam name="T">the type of the entity</typeparam>
        /// <param name="key">the key it was cached with</param>
        /// <returns>the entity requested</returns>
        public T Get <T>(ICacheKey key)
        {
            try
            {
                return((T)_globalCache[key.KeyHash()]);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(default(T));
        }
예제 #5
0
        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(ICacheKey other)
        {
            if (other != default(ICacheKey))
            {
                try
                {
                    return(other.GetType() == GetType() && other.KeyHash().Equals(KeyHash()));
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(false);
        }
        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(ICacheKey other)
        {
            if (other != default(ICacheKey))
            {
                try
                {
                    return(other.GetType() == GetType() &&
                           other.KeyHash().Equals(KeyHash()));
                }
                catch
                {
                }
            }

            return(false);
        }
예제 #7
0
 /// <summary>
 /// Get the hash code for comparison purposes
 /// </summary>
 /// <param name="obj">the thing to get the hashcode for</param>
 /// <returns>the hash code</returns>
 public int GetHashCode(ICacheKey obj)
 {
     return(obj.GetType().GetHashCode() + obj.KeyHash().GetHashCode());
 }
예제 #8
0
 /// <summary>
 /// Adds an object to the cache
 /// </summary>
 /// <param name="objectToCache">the object to cache</param>
 /// <param name="cacheKey">the key to cache it under</param>
 public void Add(object objectToCache, ICacheKey cacheKey)
 {
     Add(objectToCache, cacheKey.KeyHash());
 }
예제 #9
0
 /// <summary>
 /// Checks if an entity is in the cache
 /// </summary>
 /// <param name="key">the key of the entity</param>
 /// <returns>if it is in the cache of not</returns>
 public virtual bool Exists(ICacheKey key)
 {
     return(Exists(key.KeyHash()));
 }
예제 #10
0
        /// <summary>
        /// Removes an entity from the cache by its key
        /// </summary>
        /// <param name="key">the key of the entity to remove</param>
        public virtual void Remove <T>(ICacheKey key)
        {
            _globalCache.Remove(key.KeyHash());

            RemoveKey(key.ValueType, key);
        }
예제 #11
0
 /// <summary>
 /// Gets one entity from the cache by its key
 /// </summary>
 /// <typeparam name="T">the type of the entity</typeparam>
 /// <param name="key">the key it was cached with</param>
 /// <returns>the entity requested</returns>
 public virtual T Get <T>(ICacheKey key)
 {
     return(Get <T>(key.KeyHash()));
 }
예제 #12
0
 /// <summary>
 /// Checks if an entity is in the cache
 /// </summary>
 /// <param name="key">the key of the entity</param>
 /// <returns>if it is in the cache of not</returns>
 public bool Exists(ICacheKey key)
 {
     return(_globalCache.Get(key.KeyHash()) != null);
 }
예제 #13
0
 /// <summary>
 /// Removes an entity from the cache by its key
 /// </summary>
 /// <param name="key">the key of the entity to remove</param>
 public void Remove(ICacheKey key)
 {
     _globalCache.Remove(key.KeyHash());
 }