Flexmonster Software License Agreement (“Agreement”) has been significantly revised and is effective as of September 30, 2024.
The following modifications were made:
The modified version of Flexmonster Software License Agreement is available here.
Downloading, installing, and/or continuing to use Flexmonster Software after September 30, 2024, constitutes Licensee’s acceptance of the terms and conditions of the modified version of Flexmonster Software License 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 under License Model or Maintenance after the effective date of any 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 automatically reload indexes after any number of minutes. In this guide, we describe how to configure the Data Server as a DLL so it allows reloading indexes manually. First, we will implement a custom service for reloading indexes. Then, we will 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 (e.g., _dataStorage
) to the service:
public class IndexReloadService { private readonly IDataStorage _dataStorage; public IndexReloadService(IDataStorage dataStorage) { _dataStorage = dataStorage; } }
IDataStorage
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 is used to remove the index's data. Combine these methods to reload indexes. IDataStorage
is provided by the Data Server as a DLL.
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, explicitly set 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(""); }
Notice the Reload
method. This method is described in ReloadService.cs and is used to reload indexes.
In the sample, 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); } });
You may be interested in the following articles: