내가 아는 한 각 쿼리는 SQL 쿼리, 명령 유형 및 매개 변수에 따라 Identity
을 실행합니다. 캐시는 동시 액세스가 가능한 사전입니다.
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>();
매우 잘 작성되고 따르기 쉽고 디버깅하기 쉬운 소스 코드를 살펴보십시오. 파일을 프로젝트로 드래그하십시오.
두 번째 질문에 대한 대답은 첫 번째 질문에 대한 대답보다 나에게 분명합니다. 내가 얻은 것은 쿼리 문자열을 저장하지만 결과는 저장하지 않는다는 것입니다. 권리? ID 또는 CacheInfo에 대한 많은 문서를 찾을 수 없었습니다. 당신이 내가 이것들을 읽을 수 있다는 것을 아는 좋은 자원이 있습니까? – JCisar
소스 코드에서 가져 왔습니다. 정보를 알려주지. – Alex
고마워요! 이것은 내가 찾고 있던 것입니다. – JCisar