NCache 4.6 - Online Documentation

IReadThruProvider Interface

Create a class that implements IReadThruProvider interface and deploy it using NCache Manager. NCache framework will internally use this class to load the data from the configured data source if it is not available in the cache.
IReadThruProvider Interface
 void Dispose();
        void Init(IDictionary parameters, string cacheId);
        Dictionary<string, ProviderCacheItem> LoadFromSource(string[] keys);
        void LoadFromSource(string key, out ProviderCacheItem cacheItem);
This method will be called by NCache framework on cache startup. User can use this method for performing tasks like allocating resources, acquiring connections of data source etc. This method takes as input the IDictionay instance of  arguments passed to the provider through NCache Manger (configuration settings). It allows you to pass list of parameters to provider. These parameters can be utilized in many ways. For example, connection string of a data source can be specified as a parameter. Thus, it provides a flexible way to change the data source settings while configuring it without code changes.
The other argumentCacheId specifies the cache name for which Read-Through is configured.
This method will be called by NCache framework if the required item is not found in cache store and NCache has to load it through configured data source. This method should contain logic to load an object from configured data source. First argument "key" refers to the key of required item. The second argument is an out parameter of type Provider CacheItem which needs to be instantiate it along with required properties Here you can associate various properties to loaded item before returning it back to NCache framework. Make sure that Provider CacheItem.Value assigned in this method is "Serializable" because NCache will later save that item to cache store  to fulfill future requests.
While implementing this method, you should take care of code thread safety as multiple Get requests can access this method for Read-Through.  Also do care to avoid scenarios that cause recursive infinite loops e.g. in this method a Get request with Read-Through on the same cache handle will cause infinite recursion.
Note: In case of Get, LoadFromSource(string key, out ProviderCacheItemcacheItem) will be called from provider while for GetBulk, LoadFromSource(string[] keys)
 will be called to load items from data source.
This method will be called by NCache framework when cache stops. You can use this method for performing tasks like releasing resources, disposing connections etc. Here you can free the resources related to data source for effective resource utilization.
In NCache, Read-Through providers are configured on cache level i.e. for clustered caches all nodes will contain provider configurations and their deployed assemblies.
See Also