Beispiel #1
0
        /// <summary>
        /// 单体模式返回当前类的实例
        /// </summary>
        /// <returns></returns>
        public static YannyoCache GetCacheService()
        {
            if (instance == null)
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = CachesFileMonitor.CheckAndRemoveCache(new YannyoCache());
                    }
                }
            }

            return(instance);
        }
Beispiel #2
0
        /// <summary>
        /// 通过指定的路径删除缓存中的对象
        /// </summary>
        /// <param name="xpath">分级对象的路径</param>
        /// <param name="writeconfig">是否写入文件</param>
        public virtual void RemoveObject(string xpath, bool writeconfig)
        {
            lock (lockHelper)
            {
                try
                {
                    if (writeconfig)
                    {
                        CachesFileMonitor.UpdateCacheItem(xpath);
                    }

                    XmlNode result = objectXmlMap.SelectSingleNode(PrepareXpath(xpath));
                    //检查路径是否指向一个组或一个被缓存的实例元素
                    if (result.HasChildNodes)
                    {
                        //删除所有对象和子结点的信息
                        XmlNodeList objects  = result.SelectNodes("*[@objectId]");
                        string      objectId = "";
                        foreach (XmlNode node in objects)
                        {
                            objectId = node.Attributes["objectId"].Value;
                            node.ParentNode.RemoveChild(node);
                            //删除对象
                            cs.RemoveObject(objectId);
                        }
                    }
                    else
                    {
                        //删除元素结点和相关的对象
                        string objectId = result.Attributes["objectId"].Value;
                        result.ParentNode.RemoveChild(result);
                        cs.RemoveObject(objectId);
                    }

                    //检查并移除相应的缓存项
                }
                catch
                {    //如出错误表明当前路径不存在
                }
            }
        }
Beispiel #3
0
 private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     //检查并移除相应的缓存项
     instance = CachesFileMonitor.CheckAndRemoveCache(instance);
 }