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 ID=@id";
cmd.Parameters.Add("@id", OracleType.Int32);
cmd.Parameters["@id"].Value = key;
using (var reader = cmd.ExecuteReader())
{
}
}
}
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,
CacheStoreFactory = new OracleStoreFactory()
};
var cache = ignite.CreateCache<int, MyClass>(cacheCfg);
cache.Get(1);
}
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,下载,解压,打开 platforms\dotnet\examples\Apache.Ignite.Examples.sln)
用C#实现缓存存储的博客文章:https://ptupitsyn.github.io/Entity-Framework-Cache-Store/
在.NET中使用Oracle DB:Connecting to Oracle Database through C#?