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.
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.
ICache cache = CacheManager.GetCache("mypartitionedcache"); // Add items, perform operations cache.Clear();
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.
ICache cache = CacheManager.GetCache("myClientCache"); // Add items, perform operations cache.ClearClientCache();
NCache provides sample application for Basic Operations at:
- Shipped with NCache: %NCHOME%\samples\dotnet\BasicOperations