Skip to content

Instantly share code, notes, and snippets.

@majimenezp
Created October 17, 2013 15:43
Show Gist options
  • Save majimenezp/7027260 to your computer and use it in GitHub Desktop.
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.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();
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