MySQL cache question
#1

I have a question about MySQL cache.
Which is true?

1)
PHP код:
new Cache:result;
result mysql_query(Sql_Tquery); //query 1
//.............
result mysql_query(Sql_Tquery); //query 1
cache_delete(result); 
2)
PHP код:
new Cache:result;
result mysql_query(Sql_Tquery); //query 1
//.............
cache_delete(result);
new 
Cache:result;
result mysql_query(Sql_Tquery); //query 1
cache_delete(result); 
Reply
#2

No, wrong, You delete the cache ID tho, not the query.. check this
Reply
#3

You should delete the cache before executing another query to avoid memory leaks. The code in #2 will result in error as "result" is already defined symbol.

Example:
pawn Код:
new Cache: result, retrieved_int, retrieved_string[17];

result = mysql_query(Sql_T, "SELECT 1"); //query 1

if (cache_num_rows())
{
    cache_get_value_int(0, 0, retrieved_int);
}

cache_delete(result);

result = mysql_query(Sql_T, "SELECT 'some random text'"); //query 2

if (cache_num_rows())
{
    cache_get_value(0, 0, retrieved_string, sizeof retrieved_string);
}

cache_delete(result);
But.. store cache and delete only if you want to call cache function in between.

I notice many users hesitate to use threaded queries and prefer non-threaded queries as it was easier to convert from older version and what not. It is preferable to use threaded queries in most cases.
Reply
#4

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
No, wrong, You delete the cache ID tho, not the query.. check this
Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
You should delete the cache before executing another query to avoid memory leaks. The code in #2 will result in error as "result" is already defined symbol.

Example:
pawn Код:
new Cache: result, retrieved_int, retrieved_string[17];

result = mysql_query(Sql_T, "SELECT 1"); //query 1

if (cache_num_rows())
{
    cache_get_value_int(0, 0, retrieved_int);
}

cache_delete(result);

result = mysql_query(Sql_T, "SELECT 'some random text'"); //query 2

if (cache_num_rows())
{
    cache_get_value(0, 0, retrieved_string, sizeof retrieved_string);
}

cache_delete(result);
But.. store cache and delete only if you want to call cache function in between.

I notice many users hesitate to use threaded queries and prefer non-threaded queries as it was easier to convert from older version and what not. It is preferable to use threaded queries in most cases.
Thanks for the full description.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)