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 expiry time will be set to 48 hours by default if the value is not specified explicitly.
The segment_service reference used in the code snippet below is the segment instance created earlier.
copy
cache_service = app.cache()
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"
}
Yes
No
Send your feedback to us
Skip
Submit