Remove Cache Data with Group
Note
This feature is only available in NCache Enterprise Edition.
NCache allows the user to remove items with data groups. It also allows the user to remove data group with CacheItem.
To remove cache items that belong to a specified group, the RemoveGroupData method can be used. This method removes all cache items mapped under the group passed to this API.
Pre-Requisites
- Include the following namespace in your application:
Alachisoft.NCache.Client
Alachisoft.NCache.Runtime
Alachisoft.NCache.Runtime.Exceptions
- The application must be connected to cache before performing the operation.
- Cache must be running.
- Make sure that the data being added is serializable.
- To ensure the operation is fail safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
Important
- Passing empty strings for group will return empty result set.
- Passing null for group will throw
ArgumentNullException
. - Passing only the value of group will remove all cache items mapped under the group.
The following example removes the data under the group Important Customers. For Java, removeDataGroup removes the items belonging to the specific group.
try
{
// Pre-condition: Cache is already connected
// Items are previously added in the cache with group 'ImportantCustomers'
string groupName = "ImportantCustomers";
// Cache items belonging to the group are removed from the cache
cache.SearchService.RemoveGroupData(groupName);
}
catch (OperationFailedException ex)
{
// Exception can occur due to:
// Connection Failures
// Operation Timeout
// Operation performed during state transfer
}
catch (Exception ex)
{
// Any generic exception like ArgumentNullException or ArgumentException
}
Recommendation: To ensure the operation is fail safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
Additional Resources
NCache provides sample application for Groups at:
- GitHub
- Shipped with NCache: %NCHOME%\samples\dotnet\GroupsAndTags
See Also
Add/Update Cache Data with Groups
Retrieve Cache Data with Groups
Basic Operations for Caching Data
Tag Cache Data