Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maximgorbatyuk/4a48e227e7f47d3097860b58678059f0 to your computer and use it in GitHub Desktop.
Save maximgorbatyuk/4a48e227e7f47d3097860b58678059f0 to your computer and use it in GitHub Desktop.
/// <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