Caching Fluent NHibernate ISessionFactory

We are creating a mobile application and we are evaluating NHibernate + Fluent for use with it. The problem is that the first time we create an ISessionFactory, it takes 2 minutes. even if the table structure is very simple (3 tables).

every call after that happens very quickly.

what I would like to do is either the ISessionFactory cache between application restarts or somehow speed up its creation.

Any ideas on whether it is possible to cache? Of all my readings, not much is accelerated.

+3
source share
3 answers

, , . , , .

, .

: http://vimeo.com/16225792

24 .

+4

ISessionFactory (Shared for VB) - , - . , , , , , ...

    public class NHHelper {
        private static string _connectionString;
        private static ISessionFactory _sessionFactory;

        private static ISessionFactory SessionFactory {
            get {
                if (_sessionFactory == null) {
                            _sessionFactory = Fluently.Configure()
                                .Database(MsSqlConfiguration.MsSql2008.ShowSql()
                                    .ConnectionString(p => p.Is(_connectionString)))
                                .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(NHHelper))))
                                .BuildSessionFactory();
                }
                return _sessionFactory;
            }
        }

// this is called once upon application startup...
        public static void WarmUpSessionFactory(string connectionString) {
            _connectionString = connectionString;
            var factory = SessionFactory;
        }
// this is what you call to get a session for normal usage
        public static ISession OpenSession() {
            return SessionFactory.OpenSession();
        }
    }
+2

ISessionFactory NHibernate . ( EF LINQ-to-SQL, .) , , 2 . :

        var stopwatch = new Stopwatch();
        stopwatch.Start();
        var cfg = new Configuration();
        cfg.Configure();
        var sessionFactory = cfg.BuildSessionFactory();
        stopwatch.Stop();
        Console.WriteLine("Startup time was " + stopwatch.ElapsedMilliseconds + "ms");

, ~ 850 . 2 .

, , 2 ?

0

Source: https://habr.com/ru/post/1778017/


All Articles