/// <summary>
 /// Check MemoryCache to see if token is cached
 /// </summary>
 /// <param name="resourceId">Graph resource ID</param>
 /// <param name="tenant">Graph tenant name</param>
 /// <param name="userName">User identifier</param>
 /// <param name="authenticationResult">Authentication result object</param>
 /// <returns>True if token is cached</returns>
 private bool TryGetAccessToken(string resourceId, string tenant, string userName, out AuthenticationResult authenticationResult)
 {
     trace.TraceInformation($"Getting cached access token for resource '{resourceId}'");
     authenticationResult = (AuthenticationResult)this.accessTokenCache.Get(GetAccessTokenCacheKey(resourceId, tenant, userName));
     trace.TraceInformation($"Token retrieved: {authenticationResult?.GetHashCode()}");
     return((authenticationResult != null) && (authenticationResult.ExpiresOn > DateTime.UtcNow));
 }
        /// <summary>
        /// Cache on-behalf-of user access token
        /// </summary>
        /// <param name="resourceId">Graph resource ID</param>
        /// <param name="tenant">Graph tenant name</param>
        /// <param name="userName">User identifier</param>
        /// <param name="authenticationResult">Authentication result object</param>
        private void SetAccessTokenCache(string resourceId, string tenant, string userName, AuthenticationResult authenticationResult)
        {
            trace.TraceInformation($"Setting cached access token for resource '{resourceId}'");
            var cacheExpirationOptions =
                new MemoryCacheEntryOptions
            {
                AbsoluteExpiration = DateTime.Now.AddMinutes(ExpiryMinutes),
                Priority           = CacheItemPriority.Normal
            };

            var res = (GetAccessTokenCacheKey(resourceId, tenant, userName), authenticationResult);

            this.accessTokenCache.Set(res, DateTime.Now.ToString(), cacheExpirationOptions);

            trace.TraceInformation($"Token set: {authenticationResult?.GetHashCode()}");
        }