Created
October 17, 2013 15:43
-
-
Save majimenezp/7027260 to your computer and use it in GitHub Desktop.
Configuracion de dominio para usar redis como un 2nd level cache para fluent nhibernate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.cadConexion = System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString; | |
this.currentSession = Fluently | |
.Configure() | |
//.Database(SQLiteConfiguration.Standard.UsingFile("c:\\rfid.sqlite")) | |
.Database(PostgreSQLConfiguration.PostgreSQL82.ConnectionString(this.cadConexion)) | |
//.Database(MsSqlConfiguration.MsSql2005.ConnectionString(this.cadConexion)) | |
// aca podemos usar el provider de nuestra preferencia | |
.Cache(cache => cache.ProviderClass(typeof(NHibernate.Caches.Redis.RedisProvider).AssemblyQualifiedName).UseSecondLevelCache().UseQueryCache()) | |
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<DominioApp>()) | |
.ExposeConfiguration(BuildSchema) | |
.BuildSessionFactory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Antena TraerAntena(int idLector, int numeroAntena) | |
{ | |
Antena registro; | |
using (var sesion = this.currentSession.OpenSession()) | |
{ | |
using(var trans=this.sesion.BeginTransaction()) | |
{ | |
// la sentencia Cacheable hace que el resultado se meta al cache | |
registro = sesion.Query<Antena>() | |
.Cacheable().FirstOrDefault(x => x.Lector.Id == idLector && x.NumeroAntena == numeroAntena); | |
trans.commit(); | |
} | |
} | |
return registro; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment