Beispiel #1
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 static T Get <T>(LiveCacheKey key) where T : IEntity
        {
            try
            {
                return((T)globalCache[key.KeyHash()]);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(default(T));
        }
Beispiel #2
0
        /// <summary>
        /// Adds a single entity into the cache
        /// </summary>
        /// <param name="objectToCache">the entity to cache</param>
        public static void Add(object objectToCache)
        {
            var entityToCache = (IEntity)objectToCache;
            var cacheKey      = new LiveCacheKey(objectToCache.GetType(), entityToCache.BirthMark);

            if (!globalCache.Contains(cacheKey.KeyHash()))
            {
                globalCache.AddOrGetExisting(cacheKey.KeyHash(), objectToCache, globalPolicy);
            }
            else
            {
                globalCache.Remove(cacheKey.KeyHash());
                globalCache.Add(cacheKey.KeyHash(), objectToCache, globalPolicy);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Dumps everything of a single type into the cache from the database for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>success status</returns>
        public static bool PreLoadAll <T>() where T : IData
        {
            var backingClass = Activator.CreateInstance(typeof(T)) as IEntityBackingData;

            var implimentingEntityClass = backingClass.EntityClass;

            foreach (IData thing in DataWrapper.GetAll <T>())
            {
                var entityThing = Activator.CreateInstance(implimentingEntityClass, new object[] { (T)thing }) as IEntity;

                var cacheKey = new LiveCacheKey(implimentingEntityClass, entityThing.BirthMark);

                globalCache.AddOrGetExisting(cacheKey.KeyHash(), entityThing, globalPolicy);
            }

            return(true);
        }
Beispiel #4
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 static bool Exists(LiveCacheKey key)
 {
     return(globalCache.Get(key.KeyHash()) != null);
 }
Beispiel #5
0
 /// <summary>
 /// Removes an entity from the cache by its key
 /// </summary>
 /// <param name="key">the key of the entity to remove</param>
 public static void Remove(LiveCacheKey key)
 {
     globalCache.Remove(key.KeyHash());
 }