@@ -261,18 +261,31 @@ public bool TryGet(string key, out object value)
261261 return this . PerformTryGet ( key , out cas , out value ) . Success ;
262262 }
263263
264+ /// <summary>
265+ /// Tries to get an item from the cache.
266+ /// </summary>
267+ /// <param name="key">The identifier for the item to retrieve.</param>
268+ /// <param name="value">The retrieved item or null if not found.</param>
269+ /// <returns>The <value>true</value> if the item was successfully retrieved.</returns>
270+ public bool TryGet < T > ( string key , out T value )
271+ {
272+ ulong cas = 0 ;
273+
274+ return this . PerformTryGet ( key , out cas , out value ) . Success ;
275+ }
276+
264277 public CasResult < object > GetWithCas ( string key )
265278 {
266279 return this . GetWithCas < object > ( key ) ;
267280 }
268281
269282 public CasResult < T > GetWithCas < T > ( string key )
270283 {
271- CasResult < object > tmp ;
284+ CasResult < T > tmp ;
272285
273286 return this . TryGetWithCas ( key , out tmp )
274- ? new CasResult < T > { Cas = tmp . Cas , Result = ( T ) tmp . Result }
275- : new CasResult < T > { Cas = tmp . Cas , Result = default ( T ) } ;
287+ ? new CasResult < T > { Cas = tmp . Cas , Result = tmp . Result }
288+ : new CasResult < T > { Cas = tmp . Cas , Result = default } ;
276289 }
277290
278291 public bool TryGetWithCas ( string key , out CasResult < object > value )
@@ -287,6 +300,15 @@ public bool TryGetWithCas(string key, out CasResult<object> value)
287300 return retval . Success ;
288301 }
289302
303+ public bool TryGetWithCas < T > ( string key , out CasResult < T > value )
304+ {
305+ var retVal = PerformTryGet ( key , out var cas , out T tmp ) ;
306+
307+ value = new CasResult < T > { Cas = cas , Result = tmp } ;
308+
309+ return retVal . Success ;
310+ }
311+
290312 protected virtual IGetOperationResult PerformTryGet ( string key , out ulong cas , out object value )
291313 {
292314 var hashedKey = this . keyTransformer . Transform ( key ) ;
@@ -323,6 +345,40 @@ protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, o
323345 return result ;
324346 }
325347
348+ protected virtual IGetOperationResult PerformTryGet < T > ( string key , out ulong cas , out T value )
349+ {
350+ var hashedKey = keyTransformer . Transform ( key ) ;
351+ var node = pool . Locate ( hashedKey ) ;
352+ var result = GetOperationResultFactory . Create ( ) ;
353+
354+ cas = 0 ;
355+ value = default ;
356+
357+ if ( node != null )
358+ {
359+ var command = pool . OperationFactory . Get ( hashedKey ) ;
360+ var commandResult = node . Execute ( command ) ;
361+
362+ if ( commandResult . Success )
363+ {
364+ result . Value = value = transcoder . Deserialize < T > ( command . Result ) ;
365+ result . Cas = cas = command . CasValue ;
366+
367+ result . Pass ( ) ;
368+ return result ;
369+ }
370+
371+ commandResult . Combine ( result ) ;
372+ return result ;
373+ }
374+
375+ result . Value = value ;
376+ result . Cas = cas ;
377+
378+ result . Fail ( "Unable to locate node" ) ;
379+ return result ;
380+ }
381+
326382
327383 #region [ Store ]
328384
0 commit comments