Created
February 11, 2019 02:24
-
-
Save maximgorbatyuk/4a48e227e7f47d3097860b58678059f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Get https://localhost:5001/home/StringEqualsTest | |
/// </summary> | |
public async Task<IActionResult> StringEqualsTest() | |
{ | |
(string post1, bool isCacheHit1) = await GetValuesLower("post1"); | |
(string post2, bool isCacheHit2) = await GetValuesLower("post2"); | |
(string post1_1, bool isCacheHit1_1) = await GetValuesLower("post1"); | |
(string post1_2, bool isCacheHit1_2) = await GetValuesLower("post1"); | |
return Json(new | |
{ | |
post1, | |
isCacheHit1, | |
post2, | |
isCacheHit2, | |
post1_1, | |
isCacheHit1_1, | |
post1_2, | |
isCacheHit1_2 | |
}); | |
} | |
private async Task<(string, bool)> GetValuesEquals(string title) | |
{ | |
var debugInfo = new EFCacheDebugInfo(); | |
var post = (await _context.Posts | |
.Where(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase)) | |
.Cacheable(debugInfo) | |
.FirstOrDefaultAsync())?.Title; | |
return (post, debugInfo.IsCacheHit); | |
} | |
private async Task<(string, bool)> GetValuesUpperInvariant(string title) | |
{ | |
var debugInfo = new EFCacheDebugInfo(); | |
var post = (await _context.Posts | |
.Where(x => x.Title.ToUpperInvariant() == title.ToUpperInvariant()) | |
.Cacheable(debugInfo) | |
.FirstOrDefaultAsync())?.Title; | |
return (post, debugInfo.IsCacheHit); | |
} | |
private async Task<(string, bool)> GetValuesLower(string title) | |
{ | |
var debugInfo = new EFCacheDebugInfo(); | |
var post = (await _context.Posts | |
.Where(x => x.Title.ToLower() == title.ToLower()) | |
.Cacheable(debugInfo) | |
.FirstOrDefaultAsync())?.Title; | |
return (post, debugInfo.IsCacheHit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment