Read-Through
NCache framework will use your custom read-through provider to communicate with the back-end data source. Here, you have to implement your custom logic to load data from the configured data source. NCache will call your provider to load data from the data source behind the get call, in case of a cache miss.
Read-Through provider can be configured in following ways:
You can manually edit config.ncconf and client.ncconf located at %NCHOME%/config. %NCHOME% is NCache install directory. These files can be edited through any text editor of your choice.
Step 1: Stop Cache
Stop the cache on all servers before updating the cache settings through PowerShell using the Stop-Cache cmdlet.
Stop-Cache -Name demoClusteredCache
Step 2:
Generate the configuration for read-thru provider through Write-BackingSourceConfig cmdlet using PowerShell.
Following example generates the configurations in the specified file for read-thru provider for the class SqlReadThruProvider from the given assembly.
Write-BackingSourceConfig -AssemblyPath "C:\Program Files\NCache\samples\dotnet\BackingSource\Pr
oviders\Sql\bin\BackingSource.Providers.Sql.dll" -Class Alachisoft.NCache.Samples.Providers.SqlReadThruProvider -ReadThr
u -ProviderName sqlreader -OutputFile d:\sqlreaderconfig.xml
Note
In case of multiple read-thru providers, repeat this step for all read-thru providers.
Step 3:
Specify these read-thru providers in config.ncconf of each server by adding the configuration under the <cache-settings>
tag. Note that the configurations to be added are generated as a result of Write-BackingSourceConfig
cmdlet. If <read-thru>
is already configured, add the configurations for another <provider>
under the <read-thru>
tag.
The following example adds read-thru provider sqlreader
to the cache. Note that other settings are to be modified according to your own cache settings.
<cache-config cache-name="demoClusteredCache">
<cache-settings>
...
<backing-source>
<read-thru enable-read-thru="True">
<provider provider-name="sqlreader"
assembly-name="BackingSource.Providers.Sql,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
class-name="Alachisoft.NCache.Samples.Providers.SqlReadThruProvider"
full-name="BackingSource.Providers.Sql.dll"
default-provider="False"/>
<parameters name="connstring"
value="Data Source=20.200.20.30;Initial
Catalog=Northwind;User ID=sa;Password=***"/>
</provider>
</read-thru>
</backing-source>
...
</cache-settings>
</cache-config>
Note
Repeat this step for all server nodes.
Step 4:
Create a directory named 'deploy' in %NCHOME% if it doesn't exist already.
Note
Repeat this step for all server nodes.
Step 5:
Create a new directory in %NCHOME%/deploy and name it with the cache name.
Note
Repeat this step for all server nodes.
Step 6:
Place the provider assemblies along with all the dependent assemblies for the implementation of Read-Through in this folder.
Note
Repeat this step for all server nodes.
Step 7: Restart NCache Service
For the configuration changes made to take effect, restart NCache Service:
Make sure you have enough privileges to restart the service. If the user is not the part of the Administrator's group, make sure to run PowerShell as administrator, otherwise you might get an error message that "Cannot open ncachesvc service on computer".
Execute the following command in PowerShell to restart NCache Service:
Restart-Service -Name NCacheSvc
Step 8: Start Cache
Start the cache on all servers through PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoClusteredCache
See Also
Write-Through/Write Behind
Add Query Indexes
Create a Cache
Update Cache Config