예제 #1
0
        /// <summary>
        /// Adds a single entity into the cache
        /// </summary>
        /// <param name="objectToCache">the entity to cache</param>
        public static void Add <T>(T objectToCache) where T : IData
        {
            var entityToCache = (IData)objectToCache;
            var cacheKey      = new BackingDataCacheKey(objectToCache.GetType(), entityToCache.ID);

            BackingCache.Add(objectToCache, cacheKey);
        }
예제 #2
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>(BackingDataCacheKey key) where T : IData
 {
     return(BackingCache.Get <T>(key));
 }
예제 #3
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(BackingDataCacheKey key)
 {
     BackingCache.Remove(key);
 }
예제 #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(BackingDataCacheKey key)
 {
     return(BackingCache.Exists(key));
 }
예제 #5
0
        /// <summary>
        /// Gets one entity from the cache by its ID, only works for Singleton spawners with data templates(IEntities)
        /// </summary>
        /// <typeparam name="T">the type of the entity</typeparam>
        /// <param name="id">the id</param>
        /// <returns>the entity requested</returns>
        public static T Get <T>(long id) where T : IData
        {
            var key = new BackingDataCacheKey(typeof(T), id);

            return(Get <T>(key));
        }