日期:2014-05-20  浏览次数:20654 次

关于转xml 缓存技术、切字符串
一个系统分析员告诉我, 说他主要工作就是做网站的,就专门做类库,供下面的程序员调用
主要是访问数据库、缓存技术、转xml、切字符串 等等,代码不肯让我看,哪位做过这方面的,
能开源一下,或者在这解释一下呀,

------解决方案--------------------
数据库操作类看sqlhepler
缓存可用cache

 public class XMLUtil
{
static XmlDocument doc = new XmlDocument();

public static XMLUtil Create(string path)
{
doc.Load(path);
return new XMLUtil();
}

public XmlNode GetNode(string xpath)
{
XmlNode node = doc.SelectSingleNode(xpath);
return node;
}

public XmlNodeList GetNodeList(string xpath)
{
XmlNodeList nodeList = doc.SelectNodes(xpath);
return nodeList;
}
}

 public class CacheUtil
{
public CacheUtil()
{
}
public static bool Insert(string strKey, object valueObj, double durationSecond)
{
if (strKey != null && strKey.Length != 0 && valueObj != null)
{
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);
HttpContext.Current.Cache.Insert(strKey, valueObj, null,DateTime.Now.AddSeconds(durationSecond),System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Default,
callBack);
return true;
}
else
{
return false;
}
}
public static bool IsExist(string strKey)
{
return HttpContext.Current.Cache[strKey] != null;
}
public static object Read(string strKey)
{
if (HttpContext.Current.Cache[strKey] != null)
{
object obj = HttpContext.Current.Cache[strKey];
if (obj == null)
{
return null;
}
else
{
return obj;
}
}
else
{
return null;
}
}
public static void Remove(string strKey)
{
if (HttpContext.Current.Cache[strKey] != null)
{
HttpContext.Current.Cache.Remove(strKey);
}
}
public static void Clear()
{
IDictionaryEnumerator enu = HttpContext.Current.Cache.GetEnumerator();
while (enu.MoveNext())
{
Remove(enu.Key.ToString());
}
}
private static void onRemove(string strKey, object obj, CacheItemRemovedReason reason)
{

}
}