$setting->id, 'key' => $setting->meta_key, 'value' => $setting->meta_value, ]); } if($key === null){ $cacheable = []; foreach ($results as $model){ $cacheable[] = [ 'id' => $model->getId(), 'key' => $model->getKey(), 'value' => $model->getValue(), ]; } update_option('acpt_lite_settings_cache', $cacheable, true); } return $results; } /** * @param SettingsModel $settingsModel * @return void * @throws \Exception */ public static function save(SettingsModel $settingsModel) { $sql = " INSERT INTO `".ACPT_Lite_DB::prefixedTableName(ACPT_Lite_DB::TABLE_SETTINGS)."` (`id`, `meta_key`, `meta_value` ) VALUES ( %s, %s, %s ) ON DUPLICATE KEY UPDATE `meta_key` = %s, `meta_value` = %s ;"; ACPT_Lite_DB::executeQueryOrThrowException($sql, [ $settingsModel->getId(), $settingsModel->getKey(), $settingsModel->getValue(), $settingsModel->getKey(), $settingsModel->getValue(), ]); self::invalidateCache(); } /** * Clears both of this repository's caching layers for the unfiltered * get(null) read: ACPT_Lite_DB's own tagged phpfastcache entry, and the * acpt_settings_cache option that get(null) checks first (see get()'s * docblock for why that second layer exists). ACPT_Lite_DB::flushCache() * alone does NOT clear this option -- callers that need a guaranteed- * fresh settings read after any out-of-band change must call this too. * * @return void */ public static function invalidateCache(): void { ACPT_Lite_DB::invalidateCacheTag(self::class); delete_option('acpt_lite_settings_cache'); } }