public void TestSerializationOfReportResultCacheKey( ) { ///// // Get the AA_All Fields Report since it has rollups. ///// long reportId = Entity.GetIdFromUpgradeId(new Guid("da986865-1c90-4ae4-9a48-36cd4514208c")); var reportingInterface = new ReportingInterface( ); ReportCompletionData reportCompletion = reportingInterface.PrepareReport(reportId, new ReportSettings( )); ReportResultCacheKey reportResultCacheKey = reportCompletion.ResultCacheKey; using (var stream = new MemoryStream( )) { ProtoBuf.Serializer.Serialize(stream, reportResultCacheKey); byte [] bytes = stream.ToArray( ); using (var stream2 = new MemoryStream(bytes)) { var key2 = ProtoBuf.Serializer.Deserialize <ReportResultCacheKey>(stream2); Assert.AreEqual(key2, reportResultCacheKey); } } }
/// <summary> /// Try to get the value from cache, with logging. /// </summary> private bool TryGetOrAdd(ReportResultCacheKey key, MessageContext msg, out string result, Func <ReportResultCacheKey, string> valueFactory) { bool foundValue; foundValue = Cache.TryGetOrAdd(key, out result, valueFactory); msg.Append(() => "ReportResultCache key:" + key.ToString( )); if (foundValue) { var cacheValue = result; msg.Append(() => "ReportResultCache cache hit"); //msg.Append( ( ) => string.Format( "Entry originally cached at {0}", cacheValue.CacheTime ) ); } else { msg.Append(() => "ReportResultCache cache miss"); } return(foundValue); }