当前位置: 代码迷 >> ASP.NET >> cache能跨站共享吗解决思路
  详细解决方案

cache能跨站共享吗解决思路

热度:2434   发布时间:2013-02-25 00:00:00.0
cache能跨站共享吗
同个iis内的不同站点能跨站共享吗?



------解决方案--------------------------------------------------------
关注.帮顶.
------解决方案--------------------------------------------------------
cache是应用程序的cache,所以不能跨应用程序使用
------解决方案--------------------------------------------------------
可以采用依赖文件的方式(多个web程序依赖同一个文件作cache),请看下面的参考代码

public override void SetCache( Common.CacheType cacheType, object value )
{
SetPastExpiration( cacheType );

Context.Cache.Insert( cacheType.ToString(), value, GetCacheDependency(cacheType) );
}

public override void SetPastExpiration( Common.CacheType cacheType )
{
string filePath = GetFilePath( cacheType );

if ( File.Exists(filePath) )
{
lock ( filePath )
{
File.SetLastWriteTime( filePath, DateTime.Now );
}
}
}
  相关解决方案