私が知っている限り、各クエリは、Identity
を発行します。これは、SQLクエリ、コマンドタイプ、およびそのパラメータによって異なります。キャッシュは、同時にアクセスできる辞書です。
Dictionary<Identity, CacheInfo> _queryCache
このCacheInfo
オブジェクトはIDataReader
とIDBCommand
機能とキャッシュされた量を制限するいくつかの制御カウンタが含まれています。
サーバー側(データベーススキーマなど)はキャッシュされないため、実際には影響しません。
編集:キャッシュに使用されるIdentityクラスの様子です。
private Identity(string sql, CommandType? commandType, string connectionString, Type type, Type parametersType, Type[] otherTypes, int gridIndex)
{
this.sql = sql;
this.commandType = commandType;
this.connectionString = connectionString;
this.type = type;
this.parametersType = parametersType;
this.gridIndex = gridIndex;
unchecked
{
hashCode = 17; // we *know* we are using this in a dictionary, so pre-compute this
hashCode = hashCode * 23 + commandType.GetHashCode();
hashCode = hashCode * 23 + gridIndex.GetHashCode();
hashCode = hashCode * 23 + (sql == null ? 0 : sql.GetHashCode());
hashCode = hashCode * 23 + (type == null ? 0 : type.GetHashCode());
if (otherTypes != null)
{
foreach (var t in otherTypes)
{
hashCode = hashCode * 23 + (t == null ? 0 : t.GetHashCode());
}
}
hashCode = hashCode * 23 + (connectionString == null ? 0 : connectionString.GetHashCode());
hashCode = hashCode * 23 + (parametersType == null ? 0 : parametersType.GetHashCode());
}
}
そして、ここではCacheInfo
class CacheInfo
{
public Func<IDataReader, object> Deserializer { get; set; }
public Func<IDataReader, object>[] OtherDeserializers { get; set; }
public Action<IDbCommand, object> ParamReader { get; set; }
private int hitCount;
public int GetHitCount() { return Interlocked.CompareExchange(ref hitCount, 0, 0); }
public void RecordHit() { Interlocked.Increment(ref hitCount); }
}
そして最後にキャッシュのコンテナです。
static readonly System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo> _queryCache = new System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo>();
非常によく書かれており、フォロー/デバッグが簡単です。ファイルをプロジェクトにドラッグするだけです。
私の2番目の質問に対する答えは、私が最初の質問に与えた答えよりも明らかです。私が得たのは、クエリ文字列を格納しているが結果は格納していないということです。右?私はアイデンティティまたはCacheInfoに関する多くの文書を見つけることができませんでした。あなたが知っている良いリソースはどれですか? – JCisar
私はそれらをソースコードから取り出しました。情報を手に入れよう。 – Alex
ありがとう!これは私が探していたものです。 – JCisar