using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Threading;
namespace NPao.Tools.EntityDesign
{
public class CacheConfig
{
private static HttpRuntime _httpRuntime;
public static Cache Cache
{
get
{
EnsureHttpRuntime();
return HttpRuntime.Cache;
}
}
private static void EnsureHttpRuntime()
{
if (null == _httpRuntime)
{
try
{
Monitor.Enter(typeof(CacheConfig));
if (null == _httpRuntime)
{
// Create an Http Content to give us access to the cache.
_httpRuntime = new HttpRuntime();
}
}
finally
{
Monitor.Exit(typeof(CacheConfig));
}
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Threading;
namespace NPao.Tools.EntityDesign
{
public class CacheConfig
{
private static HttpRuntime _httpRuntime;
public static Cache Cache
{
get
{
EnsureHttpRuntime();
return HttpRuntime.Cache;
}
}
private static void EnsureHttpRuntime()
{
if (null == _httpRuntime)
{
try
{
Monitor.Enter(typeof(CacheConfig));
if (null == _httpRuntime)
{
// Create an Http Content to give us access to the cache.
_httpRuntime = new HttpRuntime();
}
}
finally
{
Monitor.Exit(typeof(CacheConfig));
}
}
}
}
}
使用:
string s = CacheConfig.Cache["txt"] as string;
if (!string.IsNullOrEmpty(s))
MessageBox.Show(s);
else
CacheConfig.Cache.Insert("txt",txtConnStr.Text);