--- title: "Insert Key Value in Cache Segment" url: https://docs.catalyst.zoho.com/en/api/code-reference/cloud-scale/cache/insert-key-value-in-segment/ description: "This API enables you to insert a key-value pair as the cache item in a cache segment." last_updated: 2026-08-17T12:16:04Z service: Cloud Scale type: api --- # Cache [Catalyst Cache](https://docs.catalyst.zoho.com/en/cloud-scale/help/cache/introduction/) is a small in-memory storage component that enables you to store data that is frequently accessed by your Catalyst application. Catalyst cache is divided into partitions or cache units called segments. Each segment stores cache items in the form of key-value pairs. # Insert a Key-Value Pair In a Cache Segment ### Description This API enables you to insert a key-value pair as the cache item in a cache segment. The segment is referred by its unique ID. The key represents the attribute and the value is the data of the cache item. You can also optionally specify the expiry time of the cache item. The default and maximum validity of a cache item is two days. > **Note:**The cache segment must already be created. You can [create a segment](https://docs.catalyst.zoho.com/en/cloud-scale/help/cache/implementation/#create-a-segment) from the Catalyst console or use the default segment. ### Request Details #### Request URL `POST` {api-domain}/baas/v1/project/{project_id}/segment/{segment_id}/cache - **api-domain** (URL): The DC-specific domain to access Catalyst API - **project_id** (Numerical): The [unique ID](https://docs.catalyst.zoho.com/en/getting-started/set-up-a-catalyst-project/general-settings/) of the project - **segment_id** (Numerical): The [unique ID](https://docs.catalyst.zoho.com/en/cloud-scale/help/cache/implementation/#create-a-segment) of the cache segment #### Request Headers **Authorization:** Zoho-oauthtoken {oauth_token} **Content-Type:** application/json **Optional Headers** **CATALYST-ORG:** {org_id} **Environment:** Development #### Scope ZohoCatalyst.cache.CREATE #### Request JSON Properties - **cache_name** (string, mandatory): Key name of the cache segment Max Size: 50 characters - **cache_value** (string, mandatory): Data value the key represents Max Size: 16000 characters - **expiry_in_hours** (long, optional): Duration of expiry in hours Max Size: 48 ### Response Details The response will return the details of the cache item such as the `cache_name`, `cache_value` and `expires_in`, along with the details of the segment it was inserted into. **Sample Request** ```bash curl -X POST \ https://api.catalyst.zoho.com/baas/v1/project/4000000006007/segment/3376000000425030/cache \ -H "Authorization: Zoho-oauthtoken 1000.910*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*16.2f*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*57" \ -H "Content-Type:application/json" \ -d ‘{ "cache_name":"counter", "cache_value":"125", "expiry_in_hours":24 }’ ``` **Sample Response** ```json { "status": "success", "data": { "cache_name": "counter", "cache_value": "125", "project_details": { "id": 4000000006007, "project_name": "ShipmentTracking", "project_type": "Live" }, "segment_details": { "id": 3376000000425030, "segment_name": "CustomerLocation" }, "expires_in": "Mar 28, 2019 02:03 AM", "expiry_in_hours": 24, "ttl_in_milliseconds": 86400000 } } ``` ### SDK Documentation [Insert Key-Value Pair- Java SDK](https://docs.catalyst.zoho.com/en/sdk/java/v1/cloud-scale/cache/insert-data-into-cache)

[Insert Key-Value Pair- Node.js SDK](https://docs.catalyst.zoho.com/en/sdk/nodejs/v2/cloud-scale/cache/insert-data-into-cache)

[Insert Key-Value Pair- Python SDK](https://docs.catalyst.zoho.com/en/sdk/python/v1/cloud-scale/cache/insert-data-into-cache)