In a distributed cache environment, it’s often crucial for certain data to be readily available in the cache as soon as the application begins execution. Typically, when a cache starts, it is empty, leading to expensive trips to the data source to fetch necessary data, which negatively impacts application performance. To address this, it’s important to preload the cache with essential reference data before the application starts using it.
Fortunately, NCache offers a Cache Startup Loader feature that allows users to implement an interface for preloading specific reference data into the cache at startup. This ensures that the application experiences fewer cache misses and minimizes trips to the data source, resulting in improved performance.

Figure 1: Cache Startup Loader with NCache
Properties of Cache Startup Loader
Every time the cache starts up, the Cache Startup Loader automatically loads data from the data source for the application to use beforehand. Therefore, before moving onto how the Cache Loader works, it’s important to understand some of its key properties:
- NCache Execution Service: Manages the loading of data from the data source into the cache at startup.
- Datasets: Allows users to group different types of data so that they can load or refresh them separately at different intervals or events to achieve parallelism.
- Dataset Assignment: Distributes datasets to nodes in a round-robin fashion to ensure efficient data loading and maximum utilization.
- Loading Mechanism: Defines which objects to load from the master data source into the cache as CacheItems during startup.
- Cache Loader Retries: Configures the number of retries for failed data loading operations.
- Cache Loader Retry Interval: Sets the time interval to wait before retrying the failed Cache Loader operations.
- On-Demand Dataset Refresh: Allows manual refreshing of datasets through the Invoke-RefresherDataset cmdlet, providing flexibility to update data.
How to Implement Cache Startup Loader?
To enable Cache Startup Loader, the user needs to implement the ICacheLoader interface. NCache uses this interface with the methods explained below to load data from the data source in the cache on cache-startup.
Initialize Cache Startup Loader
To initialize the Cache Startup Loader, the Init method is called on the Cache Startup to pass the configured parameters so that the user can use it accordingly to initialize their cache and the data source. To do so, just create the connection by opening a database connection like SQL and initialize a cache with the given name like the below sample implementation for .NET and Java.
Load Data on Cache Startup
After the successful initialization of the Cache Startup Loader, comes the LoadDatasetOnStartup method of the ICacheLoader interface. It fetches the data from the data source and adds it into the cache upon startup. It returns a user context that holds the information about the data loaded in the cache.
To learn more about the Cache Refresher, refer to the Cache Refresher documentation.
Configure Cache Loader through the NCache Management Center
Once the user has implemented the Cache Startup Loader, they can configure it through the NCache Management Center. Below is how it can be done.

Figure 2: Configure Cache Loader through the NCache Management Center
Conclusion
NCache’s Cache Startup Loader feature offers a robust solution for preloading data into your cache, ensuring that your application starts with all the necessary information readily available. This automation minimizes manual tasks and minimizes database trips, leading to faster application performance and enhanced scalability. By leveraging NCache’s capabilities, you can significantly boost your application’s efficiency and responsiveness, making it well-equipped to handle high-demand scenarios and dynamic data requirements.