Write-Through / Write-Behind
Write-Through Providers
To preserve the cache data in some persistent storage, you can configure write-through providers for a cache. By using write through provider, the cached data and data added/updated/removed is synchronized with a data source.
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 write-thru provider through Write-BackingSourceConfig cmdlet using PowerShell.
Following example generates the configurations in the specified file to configure write-thru provider for the class SqlWriteThruprovider from the given assembly.
Write-BackingSourceConfig -AssemblyPath "%NCHOME%\samples\dotnet\BackingSource\Pr
oviders\Sql\bin\BackingSource.Providers.Sql.dll" -Class Alachisoft.NCache.Samples.Providers.SqlWriteThruProvider -WriteThr
u -ProviderName sqlwriter1 -OutputFile d:\sqlwriterconfig.xml
Note
In case of multiple write-thru providers, repeat this step for all write-thru providers.
Step 3:
Specify these write-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 <write-thru>
is already configured, add the configurations for another <provider>
under the <write-thru>
tag.
The following example adds write-thru provider SqlWriteThruprovider
to the cache. Note that the cache configurations are modified according to your own cache settings.
<cache-config cache-name="demoClusteredCache">
<cache-settings>
...
<backing-source>
<write-thru enable-write-thru="True">
<provider provider-name="SqlWriteThruprovider"
assembly-name="BackingSource.Providers.Sql,
Version=1.0.0.0, Culture=neutral,PublicKeyToken=null"
class-name="Alachisoft.NCache.Samples.Providers.SqlWriteThruProvider"
full-name="BackingSource.Providers.Sql.dll"
default-provider="True">
<parameters name="connstring"
value="Data Source=20.200.20.30;Initial
Catalog=Northwind;User ID=sa;Password=***"/>
</provider>
</write-thru>
</backing-source>
...
</cache-settings>
</cache-config>
Note
Repeat this step for all server nodes.
Step 4:
Create a directory named 'deploy' in %NCHONE% 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 Write-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
- Linux:
In a terminal of your choice, execute the following command:
> sudo systemctl restart ncached
Step 8: Start Cache
Start the cache on all servers through PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoClusteredCache
Write-Behind Providers
If write-behind option is enabled, then all of the data source operations are queued up on server side and performed in the background. There are multiple settings, which can be used to optimize the write-through provider to fulfill the user requirements.
For NCache Open Source Edition, 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:
In order to configure write-behind provider make sure that write-thru provider is already configured. To add Write-Behind providers in a cache set the enable write-thru tag true like <write-thru enable-write-thru="True">
under the <backing-source>
tag in the <cache-settings>
tag. Add the <write-behind>
tag under the <write-thru>
tag with other details.
The following example enables write-behind provider for the cache. Note that the cache configurations are modified according to your own cache settings.
<cache-config cache-name="demoClusteredCache">
<cache-settings>
...
<backing-source>
<write-thru enable-write-thru="True">
...
<write-behind mode="non-batch"
failed-operations-queue-limit="5000"
failed-operations-eviction-ratio="5%"
throttling-rate-per-sec="500"/>
</write-thru>
</backing-source>
...
</cache-settings>
</cache-config>
Note
Repeat this step for all server nodes.
Step 3:
Create a directory named 'deploy' in %NCHOME%.
Note
Repeat this step for all server nodes.
Step 4:
Create a new directory in %NCHOME%/deploy and name it with the cache name.
Note
Repeat this step for all server nodes.
Step 5:
Place the provider assemblies along with all the dependent assemblies for the implementation of Write-Behind in this folder.
Note
Repeat this step for all server nodes.
Step 6: 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
- Linux:
In a terminal of your choice, execute the following command:
> sudo systemctl restart ncached
Step 7: Start Cache
Start the cache on all servers through PowerShell using the Start-Cache cmdlet.
Start-Cache -Name demoClusteredCache
See Also
Read-Through
Add Query Indexes
Create a Cache
Update Cache Config