Пример #1
0
        public object GetObjectFromCache(string cacheType, string propertyType, string key, bool loadIfEmpty = true)
        {
            object obj = null;

            if (string.IsNullOrWhiteSpace(cacheType))
            {
                throw new ArgumentException("CacheType cannot be NULL.");
            }

            if (string.IsNullOrWhiteSpace(propertyType))
            {
                throw new ArgumentException("PropertyType cannot be NULL.");
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("Key cannot be NULL.");
            }

            string cacheKey = cacheType + "." + propertyType + "." + key;

            if (cache.ContainsKey(cacheKey))
            {
                obj = cache[cacheKey].ToString();
            }
            else if (loadIfEmpty)
            {
                if (masterDataTypes.Contains(cacheType))
                {
                    obj = MasterData.GetMasterDataProperty(cacheType, propertyType, key);
                }
                else if (rqmtDataTypes.Contains(cacheType))
                {
                    obj = RQMT.GetRQMTDataProperty(cacheType, propertyType, key);
                }

                if (obj != null) // ? allow nulls in the cache? if we keep reloading the same missing item over and over that might be bad
                {
                    cache[cacheKey] = obj;
                }
            }

            return(obj);
        }