Example #1
0
 public void Update(Cache element)
 {
     using (var context = new CacheDbContext(DbContext.DbContextOptions)) {
         context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         context.Set <Cache>().Update(element);
         context.SaveChanges();
     }
 }
Example #2
0
 public void Delete(Func <Cache, bool> predicate)
 {
     using (var context = new CacheDbContext(DbContext.DbContextOptions)) {
         context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         context.Set <Cache>().RemoveRange(DbSet.AsNoTracking().Where(predicate));
         context.SaveChanges();
     }
 }
Example #3
0
 public void RemoveExpiredItems()
 {
     using (var context = new CacheDbContext(DbContext.DbContextOptions)) {
         var now = DateTime.UtcNow;
         context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
         context.Set <Cache>().RemoveRange(DbSet.AsNoTracking().Where(_ => now > _.ExpiresOn));
         context.SaveChanges();
     }
 }
Example #4
0
 public Task UpdateAsync(Cache element)
 {
     return(Task.Run(async() => {
         using (var context = new CacheDbContext(DbContext.DbContextOptions)) {
             context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
             context.Set <Cache>().Update(element);
             return await context.SaveChangesAsync();
         }
     }));
 }
Example #5
0
 public Task RemoveExpiredItemsAsync()
 {
     return(Task.Run(async() => {
         using (var context = new CacheDbContext(DbContext.DbContextOptions)) {
             var now = DateTime.UtcNow;
             context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
             context.Set <Cache>().RemoveRange(DbSet.AsNoTracking().Where(_ => now > _.ExpiresOn));
             return await context.SaveChangesAsync();
         }
     }));
 }
Example #6
0
 public CacheRepository(CacheDbContext context)
 {
     DbContext = context;
     DbSet     = context.Set <Cache>();
 }