Amazon.SessionProvider.DynamoDBSessionStateStore.DeleteExpiredSessions C# (CSharp) Method

DeleteExpiredSessions() public static method

A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance so use this method sparingly like a nightly or weekly clean job.
public static DeleteExpiredSessions ( IAmazonDynamoDB dbClient, string tableName ) : void
dbClient IAmazonDynamoDB The AmazonDynamoDB client used to find a delete expired sessions.
tableName string The table to search.
return void
        public static void DeleteExpiredSessions(IAmazonDynamoDB dbClient, string tableName)
        {
            Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider);


            ScanFilter filter = new ScanFilter();
            filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now);

            ScanOperationConfig config = new ScanOperationConfig();
            config.AttributesToGet = new List<string> { ATTRIBUTE_SESSION_ID };
            config.Select = SelectValues.SpecificAttributes;
            config.Filter = filter;

            DocumentBatchWrite batchWrite = table.CreateBatchWrite();
            Search search = table.Scan(config);

            do
            {
                List<Document> page = search.GetNextSet();
                foreach (var document in page)
                {
                    batchWrite.AddItemToDelete(document);
                }
            } while (!search.IsDone);

            batchWrite.Execute();
        }

Same methods

DynamoDBSessionStateStore::DeleteExpiredSessions ( IAmazonDynamoDB dbClient ) : void