Last active
July 10, 2020 11:53
-
-
Save mikependon/7bf7108fb13bbb5ae491f2eea2fbe153 to your computer and use it in GitHub Desktop.
RepoDb_Query_Cache_Filtered
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
/* SqConnection */ | |
var cache = CacheFactory.GetCache(); // new MemoryCache(); | |
using (var connection = new SqlConnection(connectionString).EnsureOpen()) | |
{ | |
var expirationInMinutes = 60 * 24; // 1 day | |
var products = connection.Query<Product>(e => e.CustomerId == customerId, | |
cacheKey: $"Customer-Product-{customerId}", | |
cacheItemExpiration: expirationInMinutes, | |
cache: cache); | |
} | |
/* Repository */ | |
using (var repository = new DbRepository(connectionString)) | |
{ | |
var expirationInMinutes = 60 * 24; // 1 day | |
var products = repository.QueryAll<Product>(e => e.CustomerId == customerId, | |
cacheKey: $"Customer-Product-{customerId}", | |
cacheItemExpiration: expirationInMinutes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment