Пример #1
0
 public void CreateKeyIndex()
 {
     //if ( keyIndexs == null )
     //{
     //    lock( lockObject )
     //    {
     if (keyIndexs == null)
     {
         keyIndexs = new Dictionary <string, int> (List.Count, StringComparer.InvariantCultureIgnoreCase);
         for (int i = 0, count = List.Count; i < count; i++)
         {
             CacheConfigInfo configInfo = List [i] as CacheConfigInfo;
             if (configInfo != null)
             {
                                                         #if DEBUG
                 try
                 {
                     keyIndexs.Add(configInfo.Key, i);
                 }
                 catch (Exception e)
                 {
                     ExceptionService.Current.Handle(e);
                 }
                                                         #else
                 if (!keyIndexs.ContainsKey(configInfo.Key))
                 {
                     keyIndexs.Add(configInfo.Key, i);
                 }
                                                         #endif
             }
         }
     }
     //    }
     //}
 }
Пример #2
0
        public CacheConfigInfo GetConfig(string key)
        {
            if (configs == null)
            {
#if DEBUG
                //ExceptionService.Current.Handle( new Exception( "Êý¾Ý¿â»º´æÅäÖÃÎļþ²»´æÔÚ£¡"));
                Logger.Current.Log("DataBaseCache", "Êý¾Ý¿â»º´æÅäÖÃÎļþ²»´æÔÚ£¡");
#endif

                return(null);
            }
            CacheConfigInfo cacheConfigInfo = configs.GetConfig(key);
            if (cacheConfigInfo != null)
            {
                return(cacheConfigInfo);
            }
#if DEBUG
            //ExceptionService.Current.Handle ( new Exception ( "Êý¾Ý¿â»º´æÅäÖüü²»´æÔÚ:" + key ) );
            Logger.Current.Log("DataBaseCache", "Êý¾Ý¿â»º´æÅäÖüü²»´æÔÚ:" + key);
#endif
            return(null);
        }
Пример #3
0
        public void Insert(object data, bool forceInsert)
        {
            if (enableLogCacheActivity)
            {
                System.Diagnostics.Trace.WriteLine("Insert Entered:" + cacheKey, "Cache");
                FileHelper.Log(cacheActivityLogPath, "Insert Entered:" + cacheKey);
            }

            if (data == null)
            {
                return;
            }
            CacheConfigInfo configInfo = CacheConfigs.Current.GetConfig(configKey);

            if (configInfo == null)
            {
                if (enableLogCacheActivity)
                {
                    System.Diagnostics.Trace.WriteLine("configInfo == null:" + cacheKey, "Cache");
                    FileHelper.Log(cacheActivityLogPath, "configInfo == null:" + cacheKey);
                }

                //如果没配置则不用缓存
                return;
            }
            if (!forceInsert)
            {
                if (DataProviderLazeCacheHelper.HasBeenReached(cacheKey, configInfo.ExpirationTimeMinute, configInfo.Threshold))
                {
                    DoInsert(configInfo, data);
                }
            }
            else
            {
                DoInsert(configInfo, data);
            }
        }
Пример #4
0
        private void DoInsert(CacheConfigInfo configInfo, object data)
        {
            switch (configInfo.DependencyType)
            {
            case CacheDependencyType.Time:
                CachingService.Current.Add(cacheKey, data, configInfo.ExpirationTimeMinute);                           //, new OnDataCacheRemoved () );

                #region Test
                //LJBinsTree binTree = CachedKeyDictionary [configKey] as LJBinsTree;
                //if ( binTree != null )
                //{
                //    CacheBinInfo cacheBinInfo = new CacheBinInfo ( Delimiter, cacheKey );
                //    lock ( binTree )
                //    {
                //        if ( binTree.FindNode ( cacheBinInfo, binTree.GetRoot () ) == null )
                //        {
                //            int index = cacheKey.IndexOf ( Delimiter );
                //            while ( index > 0 )
                //            {
                //                string path = cacheKey.Substring ( 0, index );
                //                CacheBinInfo binInfo = new CacheBinInfo ( Delimiter, path );
                //                if ( binTree.FindNode ( binInfo, binTree.GetRoot () ) == null )
                //                {
                //                    binTree.Insert ( binInfo );
                //                }
                //                index = cacheKey.IndexOf ( Delimiter, index + 1 );
                //            }
                //            binTree.Insert ( cacheBinInfo );
                //        }
                //    }
                //}
                //else
                //{
                //    int index = cacheKey.IndexOf ( Delimiter );
                //    if ( index > 0 )
                //    {
                //        LJBinsTree newBinTree = new LJBinsTree ();
                //        while ( index > 0 )
                //        {
                //            string path = cacheKey.Substring ( 0, index );
                //            CacheBinInfo binInfo = new CacheBinInfo ( Delimiter, path );
                //            newBinTree.Insert ( binInfo );
                //            index = cacheKey.IndexOf ( Delimiter, index + 1 );
                //        }
                //        newBinTree.Insert ( new CacheBinInfo ( Delimiter, cacheKey ) );
                //        CachedKeyDictionary.Add ( configKey, newBinTree );
                //    }
                //}
                #endregion

                if (enableLogCacheActivity)
                {
                    System.Diagnostics.Trace.WriteLine("Cache Added:" + cacheKey, "Cache");
                    FileHelper.Log(cacheActivityLogPath, "Cache Added:" + cacheKey);
                }

                break;

            case CacheDependencyType.Database:
                //CachingService.Current.Add( cacheKey, data, configInfo.GetDependency () );
                throw new NotImplementedException();
            }
        }
Пример #5
0
        private CacheConfigCollection GetConfigs()
        {
            /*
             * string cacheKey = APPLICATION_NAME;
             * CacheConfigCollection configs = CachingService.Current.Get ( cacheKey ) as CacheConfigCollection;
             * if ( configs == null )
             * {
             *      lock( lockObject )
             *      {
             *              configs = CachingService.Current.Get ( cacheKey ) as CacheConfigCollection;
             *              if ( configs == null )
             *              {
             *                      string file = null;
             *                      HttpContext context = HttpContext.Current;
             *                      if ( context != null )
             *                              file = context.Server.MapPath ( "~/" + xmlFile );
             *                      else
             *                              file = Path.Combine ( AppDomain.CurrentDomain.BaseDirectory, xmlFile );
             *
             *                      //string file = HttpContext.Current.Server.MapPath ( xmlFile );
             *                      if ( !System.IO.File.Exists ( file ) )
             *                              return null;
             *                      configs = new CacheConfigCollection ();
             *                      XmlDocument doc = new XmlDocument ();
             *                      doc.Load ( file );
             *                      XmlNode root = doc.SelectSingleNode ( "Caches" );
             *                      foreach ( XmlNode n in root.ChildNodes )
             *                      {
             *                              if ( n.NodeType != XmlNodeType.Comment )
             *                              {
             *                                      CacheConfigInfo configInfo = new CacheConfigInfo(
             *                                              n.Attributes[ "key" ].Value,
             *                                              n.Attributes[ "DependencyType" ].Value,
             *                                              n.Attributes[ "ExpirationTimeMinutes" ].Value,
             *                                              n.Attributes[ "DependencyDatabasename" ].Value,
             *                                              n.Attributes[ "DependencyTables" ].Value );
             *                                      XmlAttribute thresholdXmlAttribute = n.Attributes[ "Threshold" ];
             *                                      if ( thresholdXmlAttribute != null )
             *                                              configInfo.Threshold = Convert.ToInt32( thresholdXmlAttribute.Value );
             *                                      configs.Add ( configInfo );
             *                              }
             *                      }
             *                      configs.CreateKeyIndex ();
             *                      CachingService.Current.Add ( cacheKey, configs, file );
             *              }
             *      }
             * }
             * */
            if (configs == null)
            {
                string      file    = null;
                HttpContext context = HttpContext.Current;
                if (context != null)
                {
                    file = context.Server.MapPath("~/" + xmlFile);
                }
                else
                {
                    file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, xmlFile);
                }

                //string file = HttpContext.Current.Server.MapPath ( xmlFile );
                if (!System.IO.File.Exists(file))
                {
                    return(null);
                }
                configs = new CacheConfigCollection();
                XmlDocument doc = new XmlDocument();
                doc.Load(file);
                XmlNode root  = doc.SelectSingleNode("Caches");
                int     index = 0;
                foreach (XmlNode n in root.ChildNodes)
                {
                    if (n.NodeType != XmlNodeType.Comment)
                    {
                        index++;
                        try
                        {
                            CacheConfigInfo configInfo = new CacheConfigInfo(
                                n.Attributes ["key"].Value.ToLower(),
                                n.Attributes ["DependencyType"].Value,
                                n.Attributes ["ExpirationTimeMinutes"].Value,
                                n.Attributes ["DependencyDatabasename"].Value,
                                n.Attributes ["DependencyTables"].Value);
                            XmlAttribute thresholdXmlAttribute = n.Attributes ["Threshold"];
                            if (thresholdXmlAttribute != null)
                            {
                                configInfo.Threshold = Convert.ToInt32(thresholdXmlAttribute.Value);
                            }
                            configs.Add(configInfo);
                        }
                        catch (Exception e)
                        {
                            //ExceptionService.Current.Handle( e );
                            ExceptionService.Current.Handle(new Exception(String.Format("DataBaseCache.config: {0};/r/n{1}", n.InnerXml, e.Message)));
                        }
                    }
                }
                configs.CreateKeyIndex();
            }
            return(configs);
        }
Пример #6
0
 public bool Contains(CacheConfigInfo value)
 {
     return(List.Contains(value));
 }
Пример #7
0
 public void Remove(CacheConfigInfo value)
 {
     List.Remove(value);
 }
Пример #8
0
 public void Insert(int index, CacheConfigInfo value)
 {
     List.Insert(index, value);
 }
Пример #9
0
 public int IndexOf(CacheConfigInfo value)
 {
     return(List.IndexOf(value));
 }
Пример #10
0
 public void Add(CacheConfigInfo value)
 {
     List.Add(value);
 }