我想从数据库缓存内存中的字符串,这样我就不必每次都访问数据库.我尝试使用System.Runtime.Caching,但它似乎不起作用.
在本地站点上,缓存所有数据,但必须在辅助站点上对用户进行身份验证.一旦用户通过身份验证,它们就会被带回本地站点,但所有缓存的数据都将消失.
有没有办法解决上述问题?以下是我的代码的一部分:
using System.Runtime.Caching;
ObjectCache cache = MemoryCache.Default;
public bool CacheIsSet(string key)
{
return cache.Contains(key);
}
public object CacheGet(string key)
{
return cache.Get(key);
}
public void CacheSet(string key, object value)
{
CacheItemPolicy policy = new CacheItemPolicy();
cache.Set(key, value, policy);
}
Run Code Online (Sandbox Code Playgroud)
非常感谢.