c# Cache应用报错!
来源:百度知道 编辑:UC知道 时间:2024/05/16 09:54:52
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace CacheTest
{
class DataCache
{
Cache ch = new Cache();
public void SetCache(string key, DataCache obj)
{
ch.Insert(key, obj,null, DateTime.Now, TimeSpan.FromMinutes(20));????
}
public DataCache GetCache(string key)
{
DataCache c = new DataCache();
c=(DataCache)ch.Get(key);
return c;
}
public static void Main(string[] args)
{
DataCache dc = new DataCache();
dc.SetCache("001", dc);
DataCache dh = dc.GetCache("001");
//if (dh != null)
//{
//}
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace CacheTest
{
class DataCache
{
Cache ch = new Cache();
public void SetCache(string key, DataCache obj)
{
ch.Insert(key, obj,null, DateTime.Now, TimeSpan.FromMinutes(20));????
}
public DataCache GetCache(string key)
{
DataCache c = new DataCache();
c=(DataCache)ch.Get(key);
return c;
}
public static void Main(string[] args)
{
DataCache dc = new DataCache();
dc.SetCache("001", dc);
DataCache dh = dc.GetCache("001");
//if (dh != null)
//{
//}
m没有链接到你的数据库对象
HttpCurrent.Context.Cache.Add(.....)
是不是那里的类型没有转换啊 ,或者是不能转换啊。比如:把“ashdajsdhg”转换成时间格式!!
ch.Insert(key, obj,null, DateTime.Now, TimeSpan.FromMinutes(20));????
把他改成
ch.Insert(key, obj,null, DateTime.Now, DateTime.Now.AddMinutes(20));????
试试