Skip to content

The Cache

imshooter edited this page Nov 29, 2026 · 1 revision

Inside the public of a query, its result is the active cache. The cache_ natives read it.

forward OnPlayersRead();

public OnPlayersRead() {
    new
        name[MAX_PLAYER_NAME + 1],
        score
    ;

    for (new row, rows = cache_num_rows(); row != rows; ++row) {
        cache_get_value_name(row, "name", name);
        cache_get_value_name_int(row, "score", score);
        printf("%s has %i", name, score);
    }

    return 1;
}

Cells

  • cache_get_value_name and cache_get_value_index read a cell as text. A NULL cell reads as NULL.
  • The _int, _float and _bool natives read numbers into a variable and return false, leaving it as it was, when the cell is NULL or missing.
  • cache_is_value_name_null and cache_is_value_index_null tell whether a cell is NULL.
  • cache_get_value, cache_get_value_int, cache_get_value_float, cache_get_value_bool and cache_is_value_null read by name when the field is written between quotes, and by index otherwise.
  • cache_get_row reads the fields of a row in order into variables, with a format such as "s[37]is[64]f".

Results and fields

cache_get_row_count, cache_get_field_count and cache_get_result_count write counts into a variable, and cache_num_rows, cache_num_fields and cache_num_results return them. A query with several statements gives a result for each, chosen with cache_set_result. cache_get_field_name, cache_get_field_type and cache_get_field_index describe the fields.

Saved caches

The cache of a public is freed when the public returns. cache_save keeps it, as a new cache each time it is called. cache_set_active makes a saved cache the active one again, cache_unset_active leaves none active, and cache_delete frees it.

About the query

cache_affected_rows, cache_insert_id, cache_warning_count, cache_get_query_exec_time and cache_get_query_string tell what the query did. cache_get_errno gives its error inside the public of a failed query on a handle with ERROR_CALLBACK.

Home

Guides

Reference

Functions

Connections
Queries
Cache
JSON cells
ORM
Queries built in pieces
Prepared statements
Batches
Transactions
Passwords
Callbacks

Clone this wiki locally