Hi there,
So The ESP32 microcontroller has a specific memory space designed for this purpose. Non-volatile storage (NVS) retains data through reboots and system power loss events (using a portion of the NVS). With this method, more than 2 KBytes of data can be stored.from data sheet Jun 26, 2023
Also this demo May be helpful.
HTH
GL PJ
There is this from Epressif as well.
Non-Volatile Storage Library - ESP32-C6 - — ESP-IDF Programming Guide v5.4 documentation