using System; using System.Collections; using System.Text; using BP.En; using BP.Pub; namespace BP.DA { /// /// 实体缓存 /// public class Cache2019 { #region 缓存的操作. /// /// 清除所有的实体缓存. /// public static void ClearCache() { _hts = null; } /// /// 清除指定的缓存数据. /// /// 实体名称 public static void ClearCacheSpecEnName(string enName) { Hashtable ht = hts[enName] as Hashtable; if (ht != null) { hts.Remove(enName); } } #endregion 缓存的操作. #region 缓存ht private static Hashtable _hts; public static Hashtable hts { get { if (_hts == null) _hts = new Hashtable(); return _hts; } } #endregion #region 对实体的操作. /// /// 把实体放入缓存里面 /// /// /// /// public static void PutRow(string enName, string pkVal, Row row) { lock (lockObj) { Hashtable ht = hts[enName] as Hashtable; if (ht == null) { ht = new Hashtable(); hts.Add(enName, ht); } if (ht.ContainsKey(pkVal) == true) ht[pkVal] = row; else ht.Add(pkVal, row); } } public static void UpdateRow(string enName, string pkVal, Row row) { lock (lockObj) { Hashtable ht = hts[enName] as Hashtable; if (ht == null) { ht = new Hashtable(); hts.Add(enName, ht); } ht[pkVal] = row; } } public static void DeleteRow(string enName, string pkVal) { lock (lockObj) { Hashtable ht = hts[enName] as Hashtable; if (ht == null) { ht = new Hashtable(); hts.Add(enName, ht); } ht.Remove(pkVal.ToString()); } } private static object lockObj = new object(); /// /// 获得实体类 /// /// 实体名字 /// 键 /// row public static Row GetRow(string enName, string pkVal) { lock (lockObj) { Hashtable ht = hts[enName] as Hashtable; if (ht == null) return null; if (ht.ContainsKey(pkVal) == true) return ht[pkVal] as Row; return null; } } #endregion 对实体的操作. #region 对实体的集合操作. /// /// 把集合放入缓存. /// /// 集合实体类名 /// 实体集合 public static void PutEns(string ensName, Entities ens) { } /// /// 获取实体集合类 /// /// 集合类名 /// 主键 /// 实体集合 public static Entities GetEns(string ensName, object pkVal) { return null; } #endregion 对实体的集合操作. } }