Web services web服务中的静态缓存
这是在web服务中初始化静态缓存对象的正确方法吗Web services web服务中的静态缓存,web-services,caching,Web Services,Caching,这是在web服务中初始化静态缓存对象的正确方法吗 public class someclass{ private static Cache cache; static someclass() { cache = HttpContext.Current.Cache; } } 更多信息: Seems like I receive more then one cache object from webservice. It creates a new reques
public class someclass{
private static Cache cache;
static someclass()
{
cache = HttpContext.Current.Cache;
}
}
更多信息:
Seems like I receive more then one cache object from webservice. It creates a new request that only lasts for the duration of that call. If I move to a different machine, it creates a new request (and I think a webservice ) object that returns new cache. (because I can see two different caches being returned in the sniffer) By forcing it to be static I was hoping to have only one. However no avail. doesn't work.
这对我来说很好-尤其是当您要包装当前.Context并公开缓存值的属性时,如下所示:
public static class CacheManager
{
public static Boolean Foo
{
get { return (Boolean)HttpContext.Current.Cache["Foo"] }
set { HttpContext.Current.Cache["Foo"] = value; }
}
// etc...
}
您实际上不需要创建对当前缓存的私有引用,除非这样做只是为了节省键入时间。还请注意,我也将该类设置为静态。为什么不直接使用HTTPContext.Current.Cache访问它?似乎我从webservice接收到多个缓存对象。它创建一个新请求,该请求仅在该调用期间有效。如果我移动到另一台机器,它会创建一个新的请求,我认为是一个返回新缓存的webservice对象。通过强制它是静态的,我希望只有一个。但是没有用。那么你的机器有问题了。是否为缓存中的项目指定超时值?您的机器是否只有少量RAM?