Flexmonster Software License Agreement (“Agreement”) has been revised and is effective as of January 8, 2025.
The following modifications were made:
The modified version of Agreement is available here.
Downloading, installing, and/or continuing to use Flexmonster Software after January 8, 2025, constitutes Licensee’s acceptance of the terms and conditions of the modified version of Agreement. If Licensee does not agree to any of these terms and conditions, they must cease using Flexmonster Software and must not download, install, use, access, or continue to access Flexmonster Software. By continuing to use Flexmonster Software or renewing the license or maintenance after the effective date of these modifications to Agreement, Licensee accepts and agrees to be bound by the terms and conditions of the modified Agreement.
Out of the box, the Data Server can reload indexes only automatically after a specified number of minutes. This guide describes how to configure manual index reload in the Data Server as a DLL.
We will implement a custom service for reloading indexes and register the service in the application. We have also prepared an example of implementing and using the service.
Note Knowledge of core C# concepts is required to fully understand this guide.
Step 1.1. Create a custom service (e.g., IndexReloadService
) that will be responsible for reloading indexes:
public class IndexReloadService {}
Step 1.2. Add the IDataStorage
field to the service:
public class IndexReloadService { private readonly IDataStorage _dataStorage; public IndexReloadService(IDataStorage dataStorage) { _dataStorage = dataStorage; } }
IDataStorage
is provided by the Data Server as a DLL and describes objects responsible for storing data for indexes:
public interface IDataStorage { public Task<IDataStructure> GetOrAddAsync(string cacheKey); public void Remove(string key); }
The GetOrAddAsync()
method gets the index's data from the server's RAM. If there is no data for the index in the RAM, the method reloads the data. The Remove()
method removes the index's data. We will combine these methods to reload indexes.
Step 1.3. Declare the Reload()
method that reloads an index using the Remove()
and the GetOrAddAsync()
methods:
public class IndexReloadService
{
private readonly IDataStorage _dataStorage;
public IndexReloadService(IDataStorage dataStorage)
{
_dataStorage = dataStorage;
}
public async Task Reload(string indexName)
{
// Reload the index
_dataStorage.Remove(indexName);
await _dataStorage.GetOrAddAsync(indexName);
}
}
Register the created service (e.g., IndexReloadService
) in the Program.cs
file:
using Flexmonster.DataServer.Core;
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureFlexmonsterOptions(builder.Configuration);
builder.Services.AddFlexmonsterApi();
builder.Services.AddControllers();
builder.Services.AddCors();
builder.Services.AddScoped<IndexReloadService>();
// Other configurations
You can now use the service's Reload()
method to reload indexes manually. Check out our example server implementation, where the index is reloaded on a button click in a client-side application.
Note If you want to reload indexes only manually, disable automatic index reload by setting the DataRefreshTime and RefreshTime properties to 0
.
We prepared a sample project that demonstrates how the manual index reloading feature can be implemented.
On the server side, we created an endpoint that reloads an index on an HTTP request. On the client side, we created a button that sends the HTTP request to the endpoint and updates data on a successful response.
In the sample application, the server reloads an index when the /refresh
endpoint receives an HTTP request with the index's name. FlexmonsterAPIController.cs contains the endpoint definition:
[Route("refresh")]
[HttpGet]
public async Task<IActionResult> RefreshIndex([FromQuery]string index)
{
await _reloadService.Reload(index);
return new JsonResult("");
}
The Reload()
method is implemented in the ReloadService.cs file.
In the sample project, a user can trigger index reloading by clicking the button on the main page. An event handler is added to the button using jQuery in site.js. The handler sends a request to the /refresh
endpoint and updates the data for the report if the request succeeds:
$("#reloadButton").on("click", function () { $.ajax({ url: "http://localhost:51718/api/refresh?index=" + report.dataSource.index, type: "get", success: function () { pivot.updateData(report.dataSource); } });