NCache è una cache distribuita in memoria estremamente veloce e scalabile per .NET che memorizza nella cache i dati dell'applicazione per ridurre costosi spostamenti del database. Puoi usare NCache per rimuovere i colli di bottiglia delle prestazioni associati all'archiviazione dei dati e alla scalabilità del database.
Il modo più comune per utilizzare tale cache è consentire all'applicazione di leggere i dati dal database/origine dati e quindi memorizzarli nella cache. Dopodiché, quando l'applicazione aggiorna questi dati nel database, aggiorna anche la cache per garantire che la cache sia sincronizzata con il database.
Per di più, NCache fornisce un altro meccanismo molto potente per leggere e scrivere dati chiamato Data source Provider (Read-through/Write-through/Write-behind) per consentire NCache leggere e scrivere dati dal database.
Ci sono tre modi che puoi usare NCache in tale contesto:
Ecco alcuni vantaggi derivanti dall'utilizzo delle funzioni Read-through, Write-through e Write-behind NCache.
Ecco alcuni punti salienti di Read-through, Write-through e Write-behind in NCache.
Lo sviluppo di codice per gestori Read-through e Write-through è un processo semplice. Di seguito sono riportati esempi di interfacce per entrambi.
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;
}