Clear Cache Data
NCache allows clients to empty the cache in one call completely, without relying on data invalidation strategies like expiration and eviction. Emptying the cache results in the cache going into a "fresh" state, as all keys and associated items and metadata are removed from the cache. In case of client cache configured, NCache provides separate methods to clear the client cache, irrespective of the remote cache.
Remote Cache
The following example initializes a remote cache myPartitionedCache, performs some operations and uses the Clear() method to empty the cache synchronously. For Java, use the clear() method to clear the cache contents.
try
{
ICache cache = CacheManager.GetCache("mypartitionedcache");
// Add items, perform operations
cache.Clear();
}
catch (Exception e)
{
// Any generic exception like ArgumentNullException or ArgumentException
}
Client Cache
A client cache is a local cache synchronized with the remote clustered cache. All operations on the remote cache are synchronized with the client cache. However, you can independently clear the client cache, which will then synchronize itself with the current state of the remote cache.
The following example initializes an existing client cache myClientCache, performs some operations and uses the ClearClientCache() method to empty the client cache synchronously. For Java, NCache provides the clearClientCache() method for this purpose.
try
{
ICache cache = CacheManager.GetCache("myClientCache");
// Add items, perform operations
cache.ClearClientCache();
}
catch (Exception e)
{
// Any generic exception like ArgumentNullException or ArgumentException
}
Additional Resources
NCache provides sample application for Basic Operations at:
- GitHub
- Shipped with NCache: %NCHOME%\samples\dotnet\BasicOperations
See Also
Add Data to Cache
Update Existing Data in Cache
Retrieve Existing Cache Data
Remove Data from Cache