Example #1
0
        public static object Get <T>(string key, int?cacheDurationSeconds = null)
        {
            try
            {
                T objFromCache;

                //first check mem cache
                objFromCache = ObjectCache.GetItem <T>(key);

                if (!EqualityComparer <T> .Default.Equals(objFromCache, default(T)))
                {
                    return(objFromCache);
                }

                //at this point we know it's not in memory
                //read from file system
                objFromCache = FileCache.GetItem <T>(key, cacheDurationSeconds);

                if (!EqualityComparer <T> .Default.Equals(objFromCache, default(T)))
                {
                    return(objFromCache);
                }

                if (Azure.IsReady)
                {
                    //not in mem or file
                    //hit blob storage
                    objFromCache = Azure.GetItem <T>(key, cacheDurationSeconds);

                    if (!EqualityComparer <T> .Default.Equals(objFromCache, default(T)))
                    {
                        return(objFromCache);
                    }
                }
                //TODO: else if (AmazonS3.IsReady)

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }