Update Data in Cache

You can update the key-value pair in a cache segment using the update() method. You must pass the key name and key-value which are of the String type as arguments. If the values aren’t present, they will be inserted into the cache segment.

You can also optionally pass the expiry time parameter. The expiration time will be set to 48 hours by default if the value is not specified explicitly.

To know more about the component instance cache_service and the segment instancesegment_service used below, please refer to their respective help sections.

Parameters Used

Parameter Name Data Type Definition
cache_name String A Mandatory parameter. Will hold the key to be updated in the cache.
cache_value String A Mandatory parameter. Will hold the value of the key that has to be updated in the cache.
    
copy
#Update data in cache cache_service = app.cache() segment_service = cache_service.segment() segment_service.update('Name', 'Michael Scott')

A sample response is shown below :

    
copy
{ cache_name: "Name", cache_value: "Michael Scott", project_details: { project_name: "AlienCity", id: "2136000000007733" }, segment_details: { segment_name: "Data Store", id: "2136000000008572" }, expires_in: "Aug 18, 2021 06:46 PM", expiry_in_hours: "47", ttl_in_milliseconds: "172596000" }
Info : Refer to the SDK Scopes table to determine the required permission level for performing the above operation.

Last Updated 2025-03-28 18:24:49 +0530 +0530

ON THIS PAGE