#!/usr/bin/env bash
# onx-db-flush-query-cache — FLUSH QUERY CACHE
# Input:  {} (bos obje kabul edilir)
# Output: {"flushed":true,"operation":"FLUSH QUERY CACHE"}
# Not: MariaDB 10.3+ QUERY CACHE kaldirildi; RESET QUERY CACHE kullanilir.
# Her iki komut da denenecek; biri basarili olursa yeterli.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/_lib/common.sh"

require_root
require_cmd mysql
onx_json_input

onx_log "db-flush-query-cache: FLUSH QUERY CACHE"

# MariaDB 10.5 öncesi FLUSH QUERY CACHE, sonrasi RESET QUERY CACHE
if ! mysql_exec "" "FLUSH QUERY CACHE;" 2>/dev/null; then
    mysql_exec "" "RESET QUERY CACHE;" \
        || onx_die 3 "FLUSH/RESET QUERY CACHE basarisiz"
fi

json_ok '{"flushed":true,"operation":"FLUSH QUERY CACHE"}'
