我在我的网络应用中的几个地方使用MemoryCache来提高性能。 问题是虽然会话不应该过期,但我会不时登出。如果我将缓存提供程序更改为OrmLite,则不会发生,但整体性能会降低。 有没有办法使用OrmLite缓存提供程序来持久保持会话状态,同时继续使用MemoryCache整个应用程序。 感谢
答案 0 :(得分:0)
使用MemoryCacheClient时,只要AppDomain回收,您的会话就会丢失。
为避免这种情况,您可以使用任何其他distributed caching providers。 Redis CacheClient提供比RDBMS OrmLite缓存更好的性能。
ServiceStack仅支持为其内置组件注册单个ICacheClient
依赖项,但您仍然可以在自己的服务中注册并使用MemoryCacheClient
,例如:
container.Register(new MemoryCacheClient());
您可以像普通依赖项一样访问:
public class MyServices : Service
{
public MemoryCacheClient MemoryCache { get; set; }
public object Any(Request request)
{
return base.Request.ToOptimizedResultUsingCache(
MemoryCache, "urn:customers", () => {
return Db.Select<Customer>();
});
}
}