NCache is an extremely fast and scalable In-Memory Distributed Cache for .NET and caches application data to reduce expensive database trips. Use NCache to remove performance bottlenecks related to your data storage and database.
The most common way to use the cache is where your application reads data from your database / data source and then caches it. Then, later when your application updates the data in your database, it also updates the cache to make sure the cache is in-sync with the database.
NCache provides another very powerful mechanism for reading and writing data called Read-through / Write-through / Write-behind features to let NCache read and write data from your database.
There are three ways you can use NCache in this context:
Here are some benefits for using Read-through, Write-through, and Write-behind capability in NCache.
Here are some highlights of Read-through, Write-through, and Write-behind capability in NCache.
It is quite simple to develop Read-through and Write-through handler code. Below are examples of interfaces for both.
public interface IReadThruProvider
{
void Init(IDictionary parameters, string cacheId);
ProviderCacheItem LoadFromSource(string key);
IDictionary<string, ProviderCacheItem> LoadFromSource(ICollection<string> keys);
ProviderDataTypeItem<IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType);
void Dispose();
}
public interface ReadThruProvider extends java.lang.AutoCloseable
{
void init(java.util.Map<java.lang.String,java.lang.String> parameters, java.lang.String cacheId)
throws java.lang.Exception;
ProviderCacheItem loadFromSource(java.lang.String key) throws java.lang.Exception;
java.util.Map<java.lang.String,ProviderCacheItem> loadFromSource(java.util.Collection<java.lang.String> keys)
throws java.lang.Exception;
ProviderDataStructureItem loadDataStructureFromSource(java.lang.String key,
DistributedDataStructureType distributedDataStructureType) throws java.lang.Exception;
}
public interface IWriteThruProvider
{
void Init(IDictionary parameters, string cacheId);
OperationResult WriteToDataSource(WriteOperation operation);
ICollection<OperationResult> WriteToDataSource(ICollection<WriteOperation> operations);
ICollection<OperationResult> WriteToDataSource(ICollection<DataTypeWriteOperation> dataTypeWriteOperations);
void Dispose();
}
public interface WriteThruProvider extends java.lang.AutoCloseable
{
void init(java.util.Map<java.lang.String,java.lang.String> parameters, java.lang.String cacheId)
throws java.lang.Exception;
OperationResult writeToDataSource(WriteOperation operation) throws java.lang.Exception;
java.util.Collection<OperationResult> writeToDataSource(java.util.Collection<WriteOperation> operations)
throws java.lang.Exception;
java.util.Collection<OperationResult>
writeDataStructureToDataSource(java.util.Collection<DataStructureWriteOperation< dataStructureWriteOperations)
throws java.lang.Exception;
}