예제 #1
0
        public bool ContainsKey(string strKey)
        {
            bool blnContainsKey = false;

            if (Records.ContainsKey(strKey) == true)
            {
                CacheRecord objRecord = Records[strKey];
                if (objRecord != null)
                {
                    if (objRecord.HasExpired == true)
                    {
                        lock (_objLockObject)
                        {
                            if (Records.ContainsKey(strKey) == true)
                            {
                                Records.Remove(strKey);
                            }
                        }
                    }
                    else
                    {
                        blnContainsKey = true;
                    }
                }
            }

            return(blnContainsKey);
        }
예제 #2
0
        public TValueType GetValue <TValueType>(string strKey, TValueType objDefault)
        {
            TValueType objValue = objDefault;

            if (Records.ContainsKey(strKey) == true)
            {
                CacheRecord objRecord = Records[strKey];
                if (objRecord != null)
                {
                    if (objRecord.HasExpired == true)
                    {
                        lock (_objLockObject)
                        {
                            if (Records.ContainsKey(strKey) == true)
                            {
                                Records.Remove(strKey);
                            }
                        }
                    }
                    else
                    {
                        objValue = (TValueType)objRecord.Value;
                    }
                }
            }

            return(objValue);
        }
예제 #3
0
        public void SetValue(string strKey, object objValue, DateTime objExpirationDate)
        {
            lock (_objLockObject)
            {
                if (Records.ContainsKey(strKey) == true)
                {
                    Records.Remove(strKey);
                }

                CacheRecord objRecord = new CacheRecord(strKey, objValue, objExpirationDate);
                Records.Add(strKey, objRecord);
            }
        }