Hasta donde yo sé tiene cada consulta que emitir un Identity
, dependiendo de la consulta sql, su tipo de comando y sus parámetros. La memoria caché es un diccionario con acceso concurrente.
Dictionary<Identity, CacheInfo> _queryCache
Este objeto CacheInfo
contiene los IDataReader
y IDBCommand
funciones y algunos contadores de control que limitan la cantidad almacenada en caché.
Dado que no se almacenan en la memoria caché del lado del servidor (esquema de la base de datos, etc.), en realidad no tiene ninguna influencia.
Editar: Así es como se ve la clase Identity utilizada para el almacenamiento en caché.
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());
}
}
y aquí está la 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); }
}
Y finalmente el contenedor de la memoria caché.
static readonly System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo> _queryCache = new System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo>();
Eche un vistazo al código fuente, está muy bien escrito y es fácil de seguir/depurar. Simplemente arrastre el archivo a su proyecto.
La respuesta para mi segunda pregunta me parece más clara que la respuesta que dio a la primera pregunta. Lo que he ganado es que está almacenando la cadena de consulta, pero no los resultados. ¿Derecha? No he podido encontrar mucha documentación sobre Identity o CacheInfo. ¿Algún buen recurso que conozcas que pueda leer sobre esto? – JCisar
Los tomé del código fuente. Déjame obtener la información. – Alex
¡Gracias! Esto es justo lo que estaba buscando. – JCisar