动软.NET生成器的缓存设计

using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using Maticsoft.Model;
namespace Maticsoft.BLL
{
	/// <summary>
	/// 业务逻辑类Product 的摘要说明。
	/// </summary>
	public class Product
	{
		private readonly Maticsoft.DAL.Product dal=new Maticsoft.DAL.Product();
		public Product()
		{}
		#region  成员方法
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ProductId)
		{
			return dal.Exists(ProductId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Maticsoft.Model.Product model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Maticsoft.Model.Product model)
		{
			dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string ProductId)
		{
			
			dal.Delete(ProductId);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.Product GetModel(string ProductId)
		{
			
			return dal.GetModel(ProductId);
		}

		/// <summary>
		/// 得到一个对象实体,从缓存中。
		/// </summary>
		public Maticsoft.Model.Product GetModelByCache(string ProductId)
		{
			
			string CacheKey = "ProductModel-" + ProductId;
			object objModel = LTP.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)  //判断缓存是否过期
			{
				try
				{
					objModel = dal.GetModel(ProductId);
					if (objModel != null)
					{
						int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
						LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Maticsoft.Model.Product)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.Product> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			List<Maticsoft.Model.Product> modelList = new List<Maticsoft.Model.Product>();
			int rowsCount = ds.Tables[0].Rows.Count;
			if (rowsCount > 0)
			{
				Maticsoft.Model.Product model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Maticsoft.Model.Product();
					model.ProductId=ds.Tables[0].Rows[n]["ProductId"].ToString();
					model.CategoryId=ds.Tables[0].Rows[n]["CategoryId"].ToString();
					model.Name=ds.Tables[0].Rows[n]["Name"].ToString();
					model.Descn=ds.Tables[0].Rows[n]["Descn"].ToString();
					model.Image=ds.Tables[0].Rows[n]["Image"].ToString();
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  成员方法
	}
}
在所有model的业务层对应的BLL类中,都有一个getModelByCache(主键)的方法。
LTP.Common.DataCache类如下:
public class DataCache
{
    // Methods
    public DataCache(){}
    public static object GetCache(string CacheKey)
    {
      return HttpRuntime.Cache[CacheKey];
    }

   public static void SetCache(string CacheKey, object objObject)
  {
    HttpRuntime.Cache.Insert(CacheKey, objObject);
  }

   public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
  {
    HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
  }

 
}
 
 
 
 
 
 

转载于:https://www.cnblogs.com/cxccbv/archive/2009/07/13/1522833.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值