Пример #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());
 }