1)實施ICacheStore
接口(或繼承CacheStoreAdapter
輔助類)
public class OracleStore : CacheStoreAdapter
{
public override object Load(object key)
{
using (var con = new OracleConnection
{
ConnectionString = "User Id=<username>;Password=<password>;Data Source=<datasource>"
})
{
con.Open();
var cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE [email protected]";
cmd.Parameters.Add("@id", OracleType.Int32);
cmd.Parameters["@id"].Value = key;
using (var reader = cmd.ExecuteReader())
{
// Read data, return as object
}
}
}
public override void Write(object key, object val)
{
oracleDb.UpdateRow(key, val);
}
public override void Delete(object key)
{
oracleDb.DeleteRow(key);
}
}
2)執行存儲工廠:
public class OracleStoreFactory : IFactory<OracleStore>
{
public OracleStore CreateInstance()
{
return new OracleStore();
}
}
3)配置高速緩存來使用存儲:
using (var ignite = Ignition.Start())
{
var cacheCfg = new CacheConfiguration
{
ReadThrough = true,
WriteThrough = true,
KeepBinaryInStore = false, // Depends on your case
CacheStoreFactory = new OracleStoreFactory()
};
var cache = ignite.CreateCache<int, MyClass>(cacheCfg);
cache.Get(1); // OracleStore.Load is called.
}
的文檔Ignite.NET(在C#):https://apacheignite-net.readme.io/docs/persistent-store
C#示例的完整下載程序包可用:https://ignite.apache.org/download.cgi#binaries(點擊apache-ignite-fabric-1.9.0-bin.zip,下載,解壓縮,開放平臺\ DOTNET \例子\ Apache.Ignite.Examples.sln)
博客文章,解釋緩存存儲實現在C#: https://ptupitsyn.github.io/Entity-Framework-Cache-Store/
在.NET中使用Oracle數據庫工作:Connecting to Oracle Database through C#?
感謝您的答案,但我不明白你在哪裏設置連接對於oracle數據庫的參數,我的意思是,你把URL,用戶名和密碼放在哪裏。你能解釋我的那部分嗎?謝謝! –
我已經添加了一些更多的細節,但它不在Ignite.NET的主題中。看到這個問題的Oracle詳細信息:http://stackoverflow.com/questions/12568100/connecting-to-oracle-database-through-c –
謝謝!我會盡力而爲。 –