@@ -920,6 +920,11 @@ public IDictionary<string, T> Get<T>(IEnumerable<string> keys)
920920 return PerformMultiGet < T > ( keys , ( mget , kvp ) => this . transcoder . Deserialize < T > ( kvp . Value ) ) ;
921921 }
922922
923+ public async Task < IDictionary < string , T > > GetAsync < T > ( IEnumerable < string > keys )
924+ {
925+ return await PerformMultiGetAsync < T > ( keys , ( mget , kvp ) => this . transcoder . Deserialize < T > ( kvp . Value ) ) ;
926+ }
927+
923928 public IDictionary < string , CasResult < object > > GetWithCas ( IEnumerable < string > keys )
924929 {
925930 return PerformMultiGet < CasResult < object > > ( keys , ( mget , kvp ) => new CasResult < object >
@@ -965,10 +970,7 @@ protected virtual IDictionary<string, T> PerformMultiGet<T>(IEnumerable<string>
965970 string original ;
966971 if ( hashed . TryGetValue ( kvp . Key , out original ) )
967972 {
968- Console . WriteLine ( kvp . Key ) ;
969- Console . WriteLine ( kvp . Value ) ;
970973 var result = collector ( mget , kvp ) ;
971-
972974 // the lock will serialize the merge,
973975 // but at least the commands were not waiting on each other
974976 lock ( retval ) retval [ original ] = result ;
@@ -992,6 +994,48 @@ protected virtual IDictionary<string, T> PerformMultiGet<T>(IEnumerable<string>
992994 return retval ;
993995 }
994996
997+ protected virtual async Task < IDictionary < string , T > > PerformMultiGetAsync < T > ( IEnumerable < string > keys , Func < IMultiGetOperation , KeyValuePair < string , CacheItem > , T > collector )
998+ {
999+ // transform the keys and index them by hashed => original
1000+ // the mget results will be mapped using this index
1001+ var hashed = new Dictionary < string , string > ( ) ;
1002+ foreach ( var key in keys )
1003+ {
1004+ hashed [ this . keyTransformer . Transform ( key ) ] = key ;
1005+ }
1006+
1007+ var byServer = GroupByServer ( hashed . Keys ) ;
1008+
1009+ var retval = new Dictionary < string , T > ( hashed . Count ) ;
1010+ var tasks = new List < Task > ( ) ;
1011+
1012+ //execute each list of keys on their respective node
1013+ foreach ( var slice in byServer )
1014+ {
1015+ var node = slice . Key ;
1016+ var nodeKeys = slice . Value ;
1017+ var mget = this . pool . OperationFactory . MultiGet ( nodeKeys ) ;
1018+ var task = Task . Run ( async ( ) =>
1019+ {
1020+ if ( ( await node . ExecuteAsync ( mget ) ) . Success )
1021+ {
1022+ foreach ( var kvp in mget . Result )
1023+ {
1024+ if ( hashed . TryGetValue ( kvp . Key , out var original ) )
1025+ {
1026+ lock ( retval ) retval [ original ] = collector ( mget , kvp ) ;
1027+ }
1028+ }
1029+ }
1030+ } ) ;
1031+ tasks . Add ( task ) ;
1032+ }
1033+
1034+ await Task . WhenAll ( tasks ) ;
1035+
1036+ return retval ;
1037+ }
1038+
9951039 protected Dictionary < IMemcachedNode , IList < string > > GroupByServer ( IEnumerable < string > keys )
9961040 {
9971041 var retval = new Dictionary < IMemcachedNode , IList < string > > ( ) ;
0 commit comments