Question

J'ai essayé de mettre en œuvre les régions du cache avec Fluent NHibernate et je l'ai fait ce qui suit à ce jour:

1) la mise en cache de configuration dans Fluently.Configure ():

private static ISessionFactory CreateSessionFactory()
{
    string csStringName = Environment.MachineName;

    var nhibConfigProps = new Dictionary<string, string>();
    nhibConfigProps.Add("current_session_context_class","web");

    var cfg = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
                      .ConnectionString(c => c.FromConnectionStringWithKey(csStringName))
                      .ShowSql()
                      .Cache(cache=>cache.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider>().UseQueryCache()))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())
        .ExposeConfiguration(config => config.AddProperties(nhibConfigProps))
        .ExposeConfiguration(config=> config.EventListeners.DeleteEventListeners = new IDeleteEventListener[] {new SoftDeleteListener()})
        .ExposeConfiguration(config => new SchemaUpdate(config).Execute(false, true))
        .BuildSessionFactory();

    return cfg;
}

2) Changé ma ClassMap pour activer le cache, et définir la région de choix:

 public UserMap()
 {
     Cache.ReadWrite().Region("User");
     ...
 }

Si tout va bien je l'ai fait ce qui précède correctement, mais je ne peux pas vraiment savoir où configurer la durée de priorité et le cache pour chaque région. Savez-vous comment le faire? Et si vous arrivez à trouver des failles dans le code ci-dessus, je vous en serais reconnaissant les commentaires.

Était-ce utile?

La solution

You will need to add the priority and expiration time for this region in the syscache configuration in web/app.config. Take a look at this excellent post for a great explanation of using second level cache. The examples use vanilla NHibernate but you should get the idea - the bit about configuring syscache is at the end of the post.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top