2012-03-27 1 views
6

은 상태 here을 발견했다.정확하게 캐시 된 "정보"는 무엇입니까? 단정 한 설명서에

"제한 및

단정 그것이을 실행하는 모든 쿼리,이 신속 빠르게 개체 및 공정 변수를 구체화 할 수 있도록 정보를 캐시주의 사항 현재 구현은이 정보를 ConcurrentDictionary 객체에 캐시합니다. "

정확히 무엇을 의미합니까? 예 : 반환 된 데이터 또는 쿼리 자체 또는 두 가지 모두를 캐싱하고 있습니까?

"이 [캐시 된] 데이터는 결코 플러시되지 않습니다" "이라고 표시됩니다. 쿼리하는 테이블의 디자인 스키마가 변경되면 어떻게 "캐싱 된 정보"에 영향을 줍니까?

답변

9

내가 아는 한 각 쿼리는 SQL 쿼리, 명령 유형 및 매개 변수에 따라 Identity을 실행합니다. 캐시는 동시 액세스가 가능한 사전입니다.

Dictionary<Identity, CacheInfo> _queryCache 

CacheInfo 목적은 IDataReaderIDBCommand 기능 캐시 양을 제한하는 일부 제어 카운터를 포함한다.

서버 측 (데이터베이스 스키마 등)이 캐싱되지 않으므로 실제로 영향을 미치지 않습니다.

편집 : 캐싱에 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>(); 

매우 잘 작성되고 따르기 쉽고 디버깅하기 쉬운 소스 코드를 살펴보십시오. 파일을 프로젝트로 드래그하십시오.

+0

두 번째 질문에 대한 대답은 첫 번째 질문에 대한 대답보다 나에게 분명합니다. 내가 얻은 것은 쿼리 문자열을 저장하지만 결과는 저장하지 않는다는 것입니다. 권리? ID 또는 CacheInfo에 대한 많은 문서를 찾을 수 없었습니다. 당신이 내가 이것들을 읽을 수 있다는 것을 아는 좋은 자원이 있습니까? – JCisar

+0

소스 코드에서 가져 왔습니다. 정보를 알려주지. – Alex

+0

고마워요! 이것은 내가 찾고 있던 것입니다. – JCisar