--- title: "Delete a Key-Value Pair" url: https://docs.catalyst.zoho.com/en/sdk/java/v1/cloud-scale/cache/delete-key-value-pair/ description: "This page describes the method to delete a key-value pair using a key or cache object in your Java application with sample code snippets." last_updated: 2025-11-19T15:07:41Z service: Cloud Scale type: general related_links: - name: "Cache" url: /en/cloud-scale/help/cache/introduction --- # Delete a key-value pair When a key-value pair is no longer needed, it can be permanently deleted from the cache segment. The key-value pair cannot be restored once it is deleted,but it can be recreated. ### Delete using a key You can delete a key by passing it directly to the `deleteCacheValue()` method as a parameter. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCSegment; ``` ```java //Get a Cache Instance ZCCache cacheobj=ZCCache.getInstance(); //Get an instance of a specific segment with segment ID ZCSegment segment = cacheobj.getSegment(1510000000054091L); //Delete the Cache object using key segment.deleteCacheValue("Name"); ``` ### Delete using a cache object In this delete variant, an empty cache instance is constructed and the key value is set to it. This instance is passed as an argument to the `deleteCacheObject()` method. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.cache.ZCCache; import com.zc.component.cache.ZCCacheObject; import com.zc.component.cache.ZCSegment; ``` ```java //Get a Cache Instance ZCCache cacheobj=ZCCache.getInstance(); //Get an instance of a specific segment with segment ID ZCSegment segment = cacheobj.getSegment(1510000000054091L); //Create a CacheObject and set cache details ZCCacheObject cacheDetails = ZCCacheObject.getInstance(); cacheDetails.setKeyName("ObjectKey"); //Delete the cache using the CacheObject segment.deleteCacheObject(cacheDetails); ```