Skip to content

Instantly share code, notes, and snippets.

@mikependon
Last active July 10, 2020 11:53
Show Gist options
  • Save mikependon/7bf7108fb13bbb5ae491f2eea2fbe153 to your computer and use it in GitHub Desktop.
Save mikependon/7bf7108fb13bbb5ae491f2eea2fbe153 to your computer and use it in GitHub Desktop.
RepoDb_Query_Cache_Filtered
/* 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