I’d like to use AutoQuery against a “cached” repository in order to avoid extra db access.
My idea is to load all db rows once at the start up, having autoquery working against this “cached/InMemory” repository and reload the cached repository on a regular basis.
At the present I’m considering to use the built-in InMemory Ormlite factory filled with db entries.
public override void Configure(Container container)
{
//Config examples
this.Plugins.Add(new AutoQueryFeature
{
MaxLimit = Int32.MaxValue,
EnableRawSqlFilters = true,
UseNamedConnection = "readonly",
IllegalSqlFragmentTokens = { "ProtectedSqlFunction" },
});
//this.Plugins.Add(new CorsFeature());
var sqlDbFactory = new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings["myDb"].ConnectionString,
SqlServerOrmLiteDialectProvider.Instance);
var inMemoryDbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
sqlDbFactory.RegisterConnection("readonly", inMemoryDbFactory);
container.Register<IDbConnectionFactory>(inMemoryDbFactory);
using (var db = inMemoryDbFactory.Open())
using(var realDb = sqlDbFactory.Open())
{
if (db.CreateTableIfNotExists<Poco>())
{
foreach (var c in realDb.Select<Poco>())
{
db.Insert(c);
}
}
}
}
what do you think about it?
Is there any built-in alternative to accomplish the same goal?