private async Task RemoveGrants(PersistedGrantStorageContext context) { var found = Int32.MaxValue; while (found >= _config.TokenCleanupBatchSize) { var expiredGrants = await context.GetExpiredAsync(_config.TokenCleanupBatchSize); found = expiredGrants.Count(); _logger.LogInformation("Removing {grantCount} grants", found); if (found > 0) { foreach (var expiredGrant in expiredGrants) { try { await context.RemoveAsync(expiredGrant.Key); } catch (Exception ex) { // we get this if/when someone else already deleted the records // we want to essentially ignore this, and keep working _logger.LogDebug("Exception removing expired grants: {exception}", ex.Message); } } } else { _logger.LogDebug("No expired grants found."); } } }
public PersistedGrantStore(PersistedGrantStorageContext storageContext, ILogger <PersistedGrantStore> logger) { StorageContext = storageContext; _logger = logger; }