I use MemoryCache in several places in my web app to improve performance. The problem is that from time to time I get logged-out although the session should not have expired. If I change the cache provider to OrmLite it does not happen but the overall performance is lower. Is there a way of using OrmLite cache provider to persist session state while continuing to use MemoryCache overall the application. thanks
When using MemoryCacheClient your sessions get lost whenever the AppDomain recycling.
To avoid this you can use any of the other distributed caching providers. The Redis CacheClient offers better performance than an RDBMS OrmLite cache.
ServiceStack only supports registering a single ICacheClient
dependency for its built-in components, but you can still register and use a MemoryCacheClient
in your own Services, e.g:
container.Register(new MemoryCacheClient());
Which you can access like a normal dependency:
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>();
});
}
}