NCache 4.6 - Online Documentation

IWriteThruProvider Interface

 
Create a class that implements Alachisoft.NCache.Runtime.DatasourceProviders.IWriteThruProvider interface and deploy it using NCache Manager. NCache framework will internally use this class to perform write operation on configured data source.
 
IWriteThruProvider Interface
 
void Dispose();
 
        void Init(IDictionary parameters, string cacheId);
 
        OperationResult[] WriteToDataSource(WriteOperation[] operations);
 
        OperationResult WriteToDataSource(WriteOperation operation);
 
Member
Description
Init
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 IDictionary 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 argument CacheId specifies the cache name for which Read-Through is configured.
WriteToDataSource
This method will be called by NCache framework to perform actual write operation on configured data source.
-For Write-Through, an atomic operation with write-thru will corresponds to atomic WriteToDataSource method in provider while in case bulk operation NCache will call bulk WriteToDataSource method from provider.
-For Write-Behind, NCache will call atomic WriteToDataSource method if non-batch mode is enabled while bulk WriteToDataSource method will be called for batch mode.
 
This method should contain logic to perform operation on configured data source. The argument WriteOperation contain the  key, operation type (Add, Insert, Remove/Delete), retry count and provider cache item.
You will implement this method to perform write operations on data source according to operation type and return it to NCache as OperationResult. OperationResult holds information about:
 
·     WriteOperation: Operation performed on data source.
·     UpdateInCache flag : This flag specifies whether to update the returned write operation in cache or not. This is only applicable for Add and Insert operation types. In NCache an operation is first applied on cache store and then to data source (if write through caching is enabled). So if user wants to synchronize the cache store after updating  data source then this flag will be used.
·     Data source operation status : Write through caching basically synchronize your data source with cache store. Previously in case of operation failure on data source, item is also removed from cache, now NCache provides more flexible ways to allow user to decide whether to keep the item in cache based on these operation statuses.
·     Success: This means item was successfully added to the data source so keep it in the cache as well.
·     Failure: This means item could not be added to data source, so in case of Add/Insert operations, item will be removed from cache. Operation failure exception will be thrown to user in case of Write-Through and logged in case of write behind.
·     FailureDontRemove: This means item could not be added to the data source, but keep it in the cache. Operation failure exception will be thrown to user in case of write thru and logged in case of write behind.
·     FailureRetry: This means item could not be added to the data source, keep the item in cache and retry. In case of write thru retry will be performed as write behind operation.
While implementing this method, you should take care of code thread safety as multiple requests can access this method for Write-Through.
Dispose
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, Write-Through providers are configured on cache level i.e. for clustered caches all nodes will contain provider configurations and their deployed assemblies.
 
 
 
See Also