Components of Cache Loader/Refresher
This pages describes the components of cache loader/refresher and how to configure them for loading and refreshing data from configured data source.
ICacheLoader Interface
To configure the Cache Loader and Refresher, ICacheLoader interface needs to be implemented and then configured using the NCache Management Center or Command Line Tools. NCache uses this custom provider to load and refresh data from the configured data source.
Important
Make sure that the NCache Execution Service is running and the firewall is disabled.
The class implementing this interface allows NCache to load and refresh data from the master data source to the cache. Therefore, this class needs to implement the logic for loading the required data from your data source. The following methods are required to be defined by the classes implementing Loader and Refresher:
Member | Type | Description |
---|---|---|
Init |
void |
This method is called by NCache on startup and takes an IDictionary/Map of parameters as input which can be passed while configuring Cache Loader/Refresher. Through the input parameters, you can specify runtime parameters to your deployed provider like connection string, etc. |
LoadDatasetOnStartup |
object |
LoadDatasetOnStartup contains the logic to load data from the master data source and return an object. This method takes a string dataset that includes the data to be loaded in the cache. |
RefreshDataset |
object |
RefreshDataset contains the logic to refresh data that has been loaded in the cache. This method takes the UserContext returned by LoadDatasetOnStartup to understand which data it needs to refresh. When invoked, this method fetches fresh data from the data source based on the UserContext it receives. |
GetDatasetToRefresh |
Dictionary |
GetDatasetToRefresh takes UserContext and iterates over it to assign RefreshPreference to each dataset. It returns a dictionary containing dataset to refresh with it's respective RefreshPreference . |
Dispose |
void |
Dispose method frees up resources by disposing the Loader/Refresher. |
cache-loader tag
NCache adds the configured datasets under the <cache-loader>
tag into config.ncconf, which are then fetched in the client application.
Note
These datasets are specified through the NCache Management Center as explained in Configure Cache Startup Loader.
<cache-loader retries="0" retry-interval="0" enabled="True" refresh-on-event="False" refresh-interval="900">
<provider assembly-name="Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" class-name="Loader.Loader" full-name="Loader.dll"/>
<parameters name="connString" value="abc"/>
<datasets>
<dataset name="products" schedule-expression="0:1,5:12:00" schedule-option="Weekly"/>
<dataset name="orders" schedule-expression="0:00:00:20" schedule-option="DailyInterval"/>
<dataset name="customers" schedule-expression="0:00:00:00" schedule-option="DailyTime"/>
<dataset name="stock" schedule-expression="0:1,15,L:10:00" schedule-option="Monthly"/>
<dataset name="discount" schedule-expression="1,L:5,6:09:52" schedule-option="Monthly"/>
<dataset name="sale" schedule-expression="" schedule-option=""/>
</datasets>
</cache-loader>
Properties | Description | Format |
---|---|---|
retries |
Number of retries to perform any failed operation before the next operation. The default value is 0 seconds. | - |
retry-interval |
The time interval between each retry attempt to perform the failed operation. The default value is 0 seconds. | - |
enabled |
Determines whether the Refresher is enabled or not. The default value is False. | True/False |
refresh-on-event |
Determines whether to enable/disable poll-based refreshing. The default value is False. | True/False |
refresh-interval |
The time interval after which the refresh thread is invoked to fetch data to be refreshed. The default value is 900 seconds. | - |
assembly-name |
Human-understandable name of the deployed Cache Loader assembly. Essentially, it refers to the name of the .dll or jar file that users have identified their class libraries in. | - |
class-name |
Name of class implementing the ICacheLoader interface. |
- |
full-name |
Name of assembly to be deployed. | - |
name |
Under parameters is the name of the added parameter. |
- |
value |
Under parameters is the value of the added parameter. |
- |
name |
Under dataset is the name of the added dataset. This is a unique string . |
- |
schedule-expression |
Refresh the schedule expression of the dataset. This expression can either be for minutes, hours, days, weeks, or months. |
DailyInterval : 0:00:00:mm For DailyTime : 0:00:hh:mm For Weekly : 0:day(s):hh:mm:ss For Monthly : week(s):day(s):hh:mm |
schedule-option |
Refresh the schedule option of the added dataset. | DailyInterval / DailyTime / Weekly /Monthly |
See Also
.NET: Alachisoft.NCache.Runtime namespace.
Java: com.alachisoft.ncache.runtime.cacheloader namespace.