-
Notifications
You must be signed in to change notification settings - Fork 316
Perf | Reuse XmlWriterSettings, eliminate MemoryCacheEntryOptions allocations #3791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
e68eb7e
aa48140
cbadbe7
704fa8c
843a56e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,6 @@ internal class EnclaveSessionCache | |
| // given that for Always Encrypted scenarios, the server is considered an "untrusted" man-in-the-middle. | ||
| private long _counter; | ||
|
|
||
| // Cache timeout of 8 hours to be consistent with jwt validity. | ||
| private static int enclaveCacheTimeOutInHours = 8; | ||
|
Comment on lines
-21
to
-22
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Continue using constant (convert it to const instead) |
||
|
|
||
| // Retrieves a SqlEnclaveSession from the cache | ||
| internal SqlEnclaveSession GetEnclaveSession(EnclaveSessionParameters enclaveSessionParameters, out long counter) | ||
| { | ||
|
|
@@ -62,11 +59,8 @@ internal SqlEnclaveSession CreateSession(EnclaveSessionParameters enclaveSession | |
| lock (enclaveCacheLock) | ||
| { | ||
| enclaveSession = new SqlEnclaveSession(sharedSecret, sessionId); | ||
| MemoryCacheEntryOptions options = new MemoryCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(enclaveCacheTimeOutInHours) | ||
| }; | ||
| enclaveMemoryCache.Set<SqlEnclaveSession>(cacheKey, enclaveSession, options); | ||
| // Cache timeout of 8 hours to be consistent with JWT validity. | ||
| enclaveMemoryCache.Set<SqlEnclaveSession>(cacheKey, enclaveSession, absoluteExpirationRelativeToNow: TimeSpan.FromHours(8)); | ||
| counter = Interlocked.Increment(ref _counter); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,11 +76,7 @@ internal void AddSignatureVerificationResult(string keyStoreName, string masterK | |
| TrimCacheIfNeeded(); | ||
|
|
||
| // By default evict after 10 days. | ||
| MemoryCacheEntryOptions options = new MemoryCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(10) | ||
| }; | ||
| _cache.Set<bool>(cacheLookupKey, result, options); | ||
| _cache.Set<bool>(cacheLookupKey, result, absoluteExpirationRelativeToNow: TimeSpan.FromDays(10)); | ||
|
||
| } | ||
|
|
||
| private void ValidateSignatureNotNullOrEmpty(byte[] signature, string methodName) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,15 +236,13 @@ internal void AddQueryMetadata(SqlCommand sqlCommand, bool ignoreQueriesWithRetu | |
| } | ||
|
|
||
| // By default evict after 10 hours. | ||
| MemoryCacheEntryOptions options = new MemoryCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(10) | ||
| }; | ||
| _cache.Set<Dictionary<string, SqlCipherMetadata>>(cacheLookupKey, cipherMetadataDictionary, options); | ||
| TimeSpan expirationPeriod = TimeSpan.FromHours(10); | ||
|
||
|
|
||
| _cache.Set<Dictionary<string, SqlCipherMetadata>>(cacheLookupKey, cipherMetadataDictionary, absoluteExpirationRelativeToNow: expirationPeriod); | ||
| if (sqlCommand.requiresEnclaveComputations) | ||
| { | ||
| ConcurrentDictionary<int, SqlTceCipherInfoEntry> keysToBeCached = CreateCopyOfEnclaveKeys(sqlCommand.keysToBeSentToEnclave); | ||
| _cache.Set<ConcurrentDictionary<int, SqlTceCipherInfoEntry>>(enclaveLookupKey, keysToBeCached, options); | ||
| _cache.Set<ConcurrentDictionary<int, SqlTceCipherInfoEntry>>(enclaveLookupKey, keysToBeCached, absoluteExpirationRelativeToNow: expirationPeriod); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,11 +211,7 @@ private X509Certificate2Collection GetSigningCertificate(string attestationUrl, | |
| throw SQL.AttestationFailed(string.Format(Strings.GetAttestationSigningCertificateFailedInvalidCertificate, attestationUrl), exception); | ||
| } | ||
|
|
||
| MemoryCacheEntryOptions options = new MemoryCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1) | ||
| }; | ||
| rootSigningCertificateCache.Set<X509Certificate2Collection>(attestationUrl, certificateCollection, options); | ||
| rootSigningCertificateCache.Set<X509Certificate2Collection>(attestationUrl, certificateCollection, absoluteExpirationRelativeToNow: TimeSpan.FromDays(1)); | ||
|
||
| } | ||
|
|
||
| return rootSigningCertificateCache.Get<X509Certificate2Collection>(attestationUrl); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continue to use constant for timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - I've reintroduced the various constants in this comment and elsewhere.