Function called once (one time) in a theme when user saves settings

Is there a way to have a function called only once (one time) when the theme settings are saved.
This function is a mapping between class terms (user inputs) and their internal ID.

Basically I call

$this->api()->search('resource_classes', ['term'=>$classTerm])->getContent()[0]->id();

on each class term of the user input.
Then I need to share this mapping of settings across my theme.

I believe it is un-necessary to build the mapping (with api search) every time an item page is loaded.
Anyway, this is a matter of optimization, and it works as it is.