Extreme Performance & Linear Scalability
  • Docs /
Show / Hide Table of Contents

Using Write-Behind with Bulk Operations

Add New Items Using AddBulk API

Member Description
IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemsAdded) Adds items in cache using the default provider
IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemsAdded) Adds item in cache using the specified provider
protected void OnDataSourceItemsAdded(IDictionary iDict)
{
    //Perform appropriate actions upon response
}

private void BulkAddTest()
{
    try
    {
      String[] key = { "Customer:David:1001", "Customer:Paul:1002", "Customer:Dave:1003", "Customer:Mathew:1004" };

       //create custom objects of Product type
      CacheItem[] data = GetCacheItems(keys.Length);

      IDictionary failedItems = cache.AddBulk(keys, data, DSWriteOption.WriteBehind, OnDataSourceItemsAdded);
      //verify updated items in the main source
    }
    catch (Exception exp)
    {
        //handle exception
    }
}

Update Existing Items Using InsertBulk API

Member Description
IDictionary InsertBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback) Updates items in cache using the default provider and specified callback
IDictionary InsertBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, string providerName, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback) Updates items in cache by using the specified provider and callback
protected void OnDataSourceItemsUpdated(IDictionary iDict)
{
    //Perform appropriate actions upon response
}

private void BulkUpdateTest()
{
    try
    {
      String[] key = { "Customer:David:1001", "Customer:Paul:1002", "Customer:Dave:1003", "Customer:Mathew:1004" };

      //create new  custom objects for above mentioned keys of Product type
      CacheItem[] data = cache.GetCacheItems(keys.Length);

      IDictionary failedItems = cache.InsertBulk(keys, data, DSWriteOption.WriteBehind, OnDataSourceItemsUpdated);

        //verify updated items in the main source
    }
    catch (Exception exp)
    {
        //handle exception
    }
}

Delete Existing Items with DeleteBulk API

Member Description
void DeleteBulk(string[] keys, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemsRemovedCallback) Deletes items in cache using the default provider and specified callback
protected void OnDataSourceItemsRemoved(IDictionary iDict)
{
    //Perform appropriate actions upon response
}

private void BulkDeleteTest()
{
    try
    {
      String[] key = { "Customer:David:1001", "Customer:Paul:1002", "Customer:Dave:1003", "Customer:Mathew:1004" };

      IDictionary failedItems = cache.DeleteBulk(keys, DSWriteOption.WriteBehind, OnDataSourceItemsRemoved);
        //verify items deleted from the main source
    }
    catch (Exception exp)
    {
        //handle exception
    }
 }

 

 

 

Back to top Copyright © 2017 Alachisoft