Back to Devexpress

Hibernate a Document

aspnetcore-404119-spreadsheet-document-management-hibernate-a-document.md

latest2.4 KB
Original Source

Hibernate a Document

  • Sep 09, 2024

The DocumentManager can release server memory from inactive open documents and save them to a server’s file system. This behavior reduces server memory consumption and prevents the loss of unsaved changes should the web server restart. When a user interacts with a hibernated document, the DocumentManager restores the document from the file system to the server’s RAM.

Note

The Spreadsheet loses undo/redo history after hibernation.

To enable hibernation, call the AddHibernation method and assign a server directory path to the StoragePath property. You can configure the following optional hibernation settings:

TimeoutSpecifies the idle timeout period upon which the DocumentManager hibernates an open document. The default value is an hour.DocumentsDisposeTimeoutSpecifies how long to store hibernated documents in the server directory prior to disposal. The default value is a day.AllDocumentsOnApplicationEndSpecifies whether to hibernate all open documents at the application level.

The example below demonstrates how to configure hibernation settings as requirements dictate:

csharp
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddDevExpressControls(options => {
    options.AddSpreadsheet(
        spreadsheetOptions => {
            spreadsheetOptions
                .AddHibernation( hibernationOptions => {
                    hibernationOptions.StoragePath = Path.Combine(builder.Environment.ContentRootPath, "HibernationStorage");
                    hibernationOptions.Timeout = TimeSpan.FromMinutes(20);
                    hibernationOptions.DocumentsDisposeTimeout = TimeSpan.FromDays(2);
                    hibernationOptions.AllDocumentsOnApplicationEnd = true;
                });
        }
    );
});