Insert Data in Cache

You can insert a cache element using the put() method. This enables you to insert a key-value pair in an existing cache segment in your Catalyst project. The key name and key value are of type String and are passed as arguments to the method.

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.

The segment_service reference used below is already defined in the component instance page.

    
copy
segment_service = cache_service.segment(1234324234) segment_service.put('Name', 'Smith',2)

A sample response is shown below :

    
copy
{ cache_name: "Name", cache_value: "Smith", project_details: { project_name: "AlienCity", id: "2136000000007733" }, segment_details: { segment_name: "Location", id: "1234324234" }, expires_in: "Aug 18, 2021 06:46 PM", expiry_in_hours: "2", ttl_in_milliseconds: "172800000" }

Last Updated 2023-12-18 16:20:08 +0530 +0530

ON THIS PAGE