/// <summary> /// Deserialize a CacheModel object /// </summary> /// <param name="node"></param> /// <param name="configScope"></param> /// <returns></returns> public static CacheModel Deserialize(XmlNode node, ConfigurationScope configScope) { CacheModel model = new CacheModel(); NameValueCollection prop = NodeUtils.ParseAttributes(node, configScope.Properties); model.Id = NodeUtils.GetStringAttribute(prop, "id"); model.Implementation = NodeUtils.GetStringAttribute(prop, "implementation"); model.Implementation = configScope.SqlMapper.TypeHandlerFactory.GetTypeAlias(model.Implementation).Class.AssemblyQualifiedName; model.IsReadOnly = NodeUtils.GetBooleanAttribute(prop, "readOnly", true); model.IsSerializable = NodeUtils.GetBooleanAttribute(prop, "serialize", false); int count = node.ChildNodes.Count; for(int i=0;i<count;i++) { if (node.ChildNodes[i].LocalName=="flushInterval") { FlushInterval flush = new FlushInterval(); NameValueCollection props = NodeUtils.ParseAttributes(node.ChildNodes[i], configScope.Properties); flush.Hours = NodeUtils.GetIntAttribute(props, "hours", 0); flush.Milliseconds = NodeUtils.GetIntAttribute(props, "milliseconds", 0); flush.Minutes = NodeUtils.GetIntAttribute(props, "minutes", 0); flush.Seconds = NodeUtils.GetIntAttribute(props, "seconds", 0); model.FlushInterval = flush; } } return model; }
public void TestReturnInstanceOfCachedOject() { ICacheController cacheController = new LruCacheController(); IDictionary props = new HybridDictionary(); props.Add("CacheSize", "1"); cacheController.Configure(props); FlushInterval interval = new FlushInterval(); interval.Hours = 1; interval.Initialize(); CacheModel cacheModel = new CacheModel(); cacheModel.FlushInterval = interval; cacheModel.CacheController = cacheController; cacheModel.IsReadOnly = true; cacheModel.IsSerializable = false; Order order = new Order(); order.CardNumber = "CardNumber"; order.Date = DateTime.Now; order.LineItemsCollection = new LineItemCollection(); LineItem item = new LineItem(); item.Code = "Code1"; order.LineItemsCollection.Add(item); item = new LineItem(); item.Code = "Code2"; order.LineItemsCollection.Add(item); CacheKey key = new CacheKey(); key.Update(order); int firstId = HashCodeProvider.GetIdentityHashCode(order); cacheModel[ key ] = order; Order order2 = cacheModel[ key ] as Order; int secondId = HashCodeProvider.GetIdentityHashCode(order2); Assert.AreEqual(firstId, secondId, "hasCode different"); }
private CacheModel GetCacheModel() { CacheModel cache = new CacheModel(); cache.FlushInterval = new FlushInterval(); cache.FlushInterval.Minutes = 5; cache.Implementation = "IBatisNet.DataMapper.Configuration.Cache.Lru.LruCacheController, IBatisNet.DataMapper"; cache.Initialize(); return cache; }