Beispiel #1
0
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="objID"></param>
        /// <returns></returns>
        public static object GetObject(string objID)
        {
            if (string.IsNullOrEmpty(objID))
            {
                return(null);
            }
            if (_state == "close")
            {
                return(null);
            }

            string k    = objID.Md5();
            string path = GetCacheFile(k) + k;

            if (File.Exists(path))
            {
                FileInfo i = new FileInfo(path);
                if (i != null)
                {
                    object data = null;
                    io_lock.AcquireReaderLock();
                    try
                    {
                        FileJson j = MFSerializationUtil.Deserialize <FileJson>(File.ReadAllText(i.FullName, Encoding.UTF8));
                        if (j != null)
                        {
                            if (j.ExpireTime.CompareTo(DateTime.Now) < 0)
                            {
                                File.Delete(i.FullName);
                            }

                            else
                            {
                                data = j.Obj;
                            }
                        }
                    }

                    catch
                    { }

                    finally
                    {
                        io_lock.ReleaseReaderLock();
                    }

                    return(data);
                }
            }

            return(null);
        }