Exemplo n.º 1
0
        /// <summary>
        /// Method to get a specific Model based on the given type
        /// </summary>
        /// <typeparam name="T">model type</typeparam>
        /// <returns>cached model or null if not cached</returns>
        public IModel GetModel <T>() where T : class, IModel, new()
        {
            CacheModel <IModel> cachedModel = CachedRequestResults.GetListedCachedModel <CacheModel <IModel>, T>();

            if (cachedModel == null)
            {
                return(default(T));
            }


            TimeSpan goneTime = DateTime.Now - cachedModel.TimeStamp;

            // Delete all elements, where the request is longer than X in the history
            if (MoreThanXMinutesElapsed(goneTime, cachedModel.MinutesToStore))
            {
                cachedModel = null;
            }

            // Check if the request is still cached
            return(cachedModel?.Model);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Method to set a specific model based on the given type
 /// </summary>
 /// <typeparam name="T">model type</typeparam>
 /// <param name="model">mode lto be cached</param>
 public void SetModel <T>(IModel model) where T : IModel, new()
 {
     CachedRequestResults.SetListedCachedModel <T>(model);
 }