Configure Startup Cache Loader and Refresher
The cache loader and refresher can be configured by adding cache loaders and refreshers using the NCache Management Center and deploying them accordingly. You may also add and remove datasets as their importance rises and falls.
Note
Before configuring the cache loader and refresher, make sure that the cache is stopped.
Configure Cache Loader and Refresher Using the NCache Management Center
Launch the NCache Management Center by browsing to http://localhost:8251 or
<server-ip>:8251
on Windows and Linux.In the left navigation bar, click on Clustered Caches or Local Caches based on the cache to configure.
Against the cache name, click on View Details.
This opens up the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Cache Loader/Refresher in the left bar.
Check the Enable Cache Loader and Refresher checkbox to enable other configuration options.
Configure the Cache Loader
Important
For Java, before deploying your JAR files, ensure that your Environment Variable for Java Home is set and have the appropriate JDK installed as discussed in the NCache Installation Guide.
- Click on the Browse button against Assembly Name to select the assembly implementing the
ICacheLoader
interface.
The name of the selected assembly will appear in Assembly Name and any classes implementing the user-defined interface will be listed in the Class Name list box.
Select the required class.
You can also add the parameters for your cache loader implementation, if required. Provide the Parameter name and Value and click on + to add the parameters. These will be displayed in the box with the option to remove the parameter.
Note
Specifying parameters is optional. It is only required if your implementation of ICacheLoader
requires parameter(s) during initialization.
- You can add Datasets to your loader implementation as well. A Dataset is a way for you to group similar data - so it loads together. This also makes refreshing the data easier. Under the Datasets section, click on the Add Dataset button. This will take you to the following screen, where you need to give your dataset a meaningful name.
- Click on OK and Save Changes to save your cache loader's configuration.
Configure the Cache Refresher
To configure the Cache Refresher, you must provide Datasets to your implementation, in the same way you've done for the Cache Loader.
Refreshing any dataset is optional. But if you plan on using Cache Refresher to refresh the dataset, you need to check the Refresh this dataset at the following schedule checkbox.
You have the following four refresh scheduling options available:
- Interval: Interval-based scheduling allows you to specify a recurring time after which you want the Execution service to refresh your dataset. This option takes value in minutes which are counted after the cache starts.
- Daily: The daily scheduling option allows you to specify the exact time of the day at which you want the Execution service to refresh your dataset. This option provides you with a time chart, making it easier for you to choose the time. The time specified will be the local time of your coordinator node.
- Weekly: The weekly option allows you to specify the time as well as days of the week on which you want the Execution service to refresh your dataset. You can choose the time from the time chart and select the days from the list on the NCache Management Center.
- Monthly: Monthly scheduling of Cache Refresher allows you to specify the time stamp, as well as the days of a month on which you want the Execution service to refresh your loaded dataset. You have the following two ways of selecting the days:
- You can either specify the exact day of the month (as in number) OR
- You can select weeks and their respective days.
Select the refresh schedule of your preference and click on the OK button to add the custom dataset to your Loader/Refresher implementation.
Note
- Repeat the same process if you want to add more than one dataset.
- To edit or remove a dataset, click on the Actions button against the dataset to perform the desired operation.
Under the Options section, you have multiple configurable options to customize the Cache Refresher usage.
- Refresh Interval: This term refers to the interval after which the dedicated thread checks the cache for any datasets to refresh. By default, the refresh interval is 900 seconds. You may specify a different value using the Refresh-Interval box.
Note
The recommended value of the refresh interval is at least 600 seconds.
Number of Retries: This is the number of times NCache attempts a failed operation after its initial failure. By default, the number of retries is 0. You can specify if you want NCache to perform any failed operation again before proceeding to the next. Specify this number in the No. of Retries box.
Retry Interval: This is the interval by which the user determines how long to wait before trying to execute a failed operation. By default, the retry interval is 0 seconds, but you can configure it by adding a value in the Retry-Interval box.
Poll-Based Refresh Interval: You can also implement your method to trigger poll-based dataset refreshing. This is your custom implementation that is triggered after every Refresh Interval and returns a list of datasets that should either be refreshed immediately or within 24 hours. To enable this poll-based refreshing, check the "Poll for dataset names to refresh at every refresh interval" checkbox.
Note
NCache allows the user to manually refresh a pre-configured dataset at runtime when desired through the NCache Management Center.
Deploy Cache Loader
Once the configurations have been made, now you have to Deploy Cache Loader to copy the cache loader and refresher assemblies to all sever nodes. To deploy the Cache Loader, follow the steps mentioned below:
- Click on Deploy Cache Loader button.
Browse for required assemblies.
After you have selected the desired assemblies, save all the configurations to apply the changes.
Note
If there is a change in the provider code, you must redeploy the provider. For the Java Edition, you need to stop the NCache Execution Service, deploy the provider, and then restart the NCache Execution Service.
Add the Startup Loader
The Add Startup Loader tool enables the users to configure the startup loader and refresher provider for the cache which loads the configured datasets from the data source to the cache whenever the cache starts.
This command configures a startup loader for a cache named demoCache. The assemblies to be deployed are placed at the specified path and the default port 8250.
add-startuploader -cachename demoCache -assemblypath /usr/share/Provider.jar -class StartupLoader.Loader
Add the Loader Dataset
The Add Loader Dataset tool enables the users to add datasets to a cache with cache loader and cache refresher configured.
This adds dataset on cache loader/refresher configured demoCache that will refresh itself after an interval of 5 minutes from cache start.
add-loaderdataset -dataset order -cachename demoCache -scheduleexpression 0:00:00:05 -scheduleoption DailyInterval
Remove the Loader Dataset
The Remove Loader Dataset tool enables users to remove dataset from the cache with enabled cache startup loader and cache refresher.
This removes a dataset from a cache named demoCache.
Remove the Startup Loader
The Remove Startup Loader tool enables the users to remove the preconfigured loader and refresher from the specified cache.
It removes the startup loader/refresher for the cache named demoCache using the default port.
See Also
Register Classes for Portable Data Sharing
Register Classes for Compact Serialization
Compression