Interface IReadThruProvider
Contains methods used to read an object by its key from the master data source. Must be implemented by read-through components.
Assembly: Alachisoft.NCache.Runtime.dll
Syntax
public interface IReadThruProvider
              Methods
Dispose()
Perform tasks associated with freeing, releasing, or resetting resources.
Declaration
void Dispose()
              Examples
The following example disconnects from the data source on dispose.
public void Dispose()
{
   _source.DisConnect();
}
              
              
              
              Init(IDictionary, String)
Perform tasks like allocating resources or acquiring connections, etc.
Declaration
void Init(IDictionary parameters, string cacheId)
              Parameters
| Type | Name | Description | 
|---|---|---|
| System.Collections.IDictionary | parameters | Startup parameters defined in the configuration.  | 
                  
| System.String | cacheId | Id of the cache.  | 
                  
Examples
The following example connects to the data source.
public void Init(IDictionary parameters, string cacheId)
{
   object connString = parameters["connstring"];
   _source.Connect(connString == null ? "" : connString.ToString());
}
              
              
              
              LoadDataTypeFromSource(String, DistributedDataType)
Responsible for loading the list from the data source. Name is passed as a parameter.
Declaration
ProviderDataTypeItem<IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
              Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | key | Key used to reference the object.  | 
                  
| DistributedDataType | dataType | Type of collection.  | 
                  
Returns
| Type | Description | 
|---|---|
| ProviderDataTypeItem<System.Collections.IEnumerable> | A CacheItem with limited fields.  | 
                  
Examples
The following example performs operation to load the specified data type from the data source.
public ProviderDataTypeItem<IEnumerable> LoadDataTypeFromSource(string key, DistributedDataType dataType)
{
    IEnumerable value = null;
    ProviderDataTypeItem<IEnumerable> dataTypeItem = null;
    switch (dataType)
    {
        case DistributedDataType.List:
            value = new List<object>()
        {
            LoadFromDataSource(key)
        };
            dataTypeItem = new ProviderDataTypeItem<IEnumerable>(value);
            break;
        case DistributedDataType.Dictionary:
            value = new Dictionary<string, object>()
        {
            { key ,  LoadFromDataSource(key) }
        };
            dataTypeItem = new ProviderDataTypeItem<IEnumerable>(value);
            break;
        case DistributedDataType.Counter:
            dataTypeItem = new ProviderDataTypeItem<IEnumerable>(1000);
            break;
    }
    return dataTypeItem;
}
private object LoadFromDataSource(string key)
{
    // Load item from your data source and return retrieved Object
    return _source.LoadObject(key);
}
              
              
              
              LoadFromSource(ICollection<String>)
Responsible for loading array of objects from the data source. Keys are passed as a parameter.
Declaration
IDictionary<string, ProviderCacheItem> LoadFromSource(ICollection<string> keys)
              Parameters
| Type | Name | Description | 
|---|---|---|
| System.Collections.Generic.ICollection<System.String> | keys | Array of keys.  | 
                  
Returns
| Type | Description | 
|---|---|
| System.Collections.Generic.IDictionary<System.String, ProviderCacheItem> | 
Examples
The following example performs multiple operations on data source.
public IDictionary<string, ProviderCacheItem> LoadFromSource(ICollection<string> keys)
{
    Dictionary<string, ProviderCacheItem> dictionary = new Dictionary<string, ProviderCacheItem>();
    foreach (string key in keys)
    {
        ProviderCacheItem item = LoadFromSource(key);
        dictionary.Add(key, item);
    }
     return dictionary;
}
              
              
              
              LoadFromSource(String)
Responsible for loading the object from the data source. Key is passed as a parameter.
Declaration
ProviderCacheItem LoadFromSource(string key)
              Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | key | Key used to reference the object.  | 
                  
Returns
| Type | Description | 
|---|---|
| ProviderCacheItem | A CacheItem with some limited fields.  | 
                  
Examples
The following example performs a single operation on the data source.
public ProviderCacheItem LoadFromSource(string key)
{   
    return new ProviderCacheItem(_source.LoadCustomer(key));
}