I'm developing a website using Asp .Net MVC and NHibernate as ORM tool. I just implemented some patterns using some principles. These are IoC, Service-Repository and UoW.
I'm using almost all features of NHibernate in terms of Caching like below
- Lazy Loading
- 2nd Level Cache
- Query Cache
- Entity Cache
Up to now everything was fine, I can load whole web site in 1 second almost 7,5 MB size in total(mostly images from Azure Storage) without Asp .Net MVC 's outputcache with above infrastructure but this action is happening when i load the web site for the second time.
The big problem is NHibernate SessionFactory adds almost 15 seconds to uptime of the project when it's first load and this is unacceptable.
I have 25 entities and so their mappings actually, why it takes so much time for the first time?
Here my configuration for Nhibernate
public static ISessionFactory GetSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012
.Raw("connection.isolation", "ReadCommitted")
.ConnectionString("connectionString")
.Mappings(gX => gX.FluentMappings.AddFromAssemblyOf<MyEntity>())
.Cache(gX => gX.ProviderClass<SysCacheProvider>()
.UseSecondLevelCache()
.UseQueryCache())
.BuildSessionFactory();
}
I don't have any problem of the create process of the SessionFactory by the way. The only problem is the up time of my project for the first time. I just solved many problems about with caching strategies but couldn't figured out the SessionFactory.
Any idea or suggestion about it? Thanks