What exactly is “information” that eclipses caching?

The Dapper documentation found here says:

" Limitations and reservations

Dapper caches information about all requests that are executed , which allows you to quickly and quickly process objects and quickly process parameters. The current implementation caches this information in the ConcurrentDictionary object. "

What exactly does this mean? Example: caching the returned data or the request itself or the bits of both?

It also states that " this [cached] data is never flushed ." How does this affect “cached information” if the design scheme for the tables (tables) you request is changed?

+6
source share
1 answer

As far as I know, each query issues Identity , depending on the SQL query, its type of command and its parameters. A cache is a parallel access dictionary.

 Dictionary<Identity, CacheInfo> _queryCache 

This CacheInfo object contains the IDataReader and IDBCommand and some watch counters that limit the cached amount.

Since the server side (database schema, etc.) is not cached, it actually has no effect.

Edit: The way the Identity class looks for caching.

 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()); } } 

And here is 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); } } 

And finally, the cache container.

 static readonly System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo> _queryCache = new System.Collections.Concurrent.ConcurrentDictionary<Identity, CacheInfo>(); 

Look at the source code, it is very well written and easy to follow / debug. Just drag and drop the file into your project.

+9
source

Source: https://habr.com/ru/post/911801/


All Articles