MySQL cache question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL cache question (
/showthread.php?tid=656028)
MySQL cache question -
MRM - 05.07.2018
I have a question about MySQL cache.
Which is true?
1)
PHP код:
new Cache:result;
result = mysql_query(Sql_T, query); //query 1
//.............
result = mysql_query(Sql_T, query); //query 1
cache_delete(result);
2)
PHP код:
new Cache:result;
result = mysql_query(Sql_T, query); //query 1
//.............
cache_delete(result);
new Cache:result;
result = mysql_query(Sql_T, query); //query 1
cache_delete(result);
Re: MySQL cache question -
JasonRiggs - 05.07.2018
No, wrong, You delete the cache ID tho, not the query.. check
this
Re: MySQL cache question -
Calisthenics - 05.07.2018
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.
Re: MySQL cache question -
MRM - 06.07.2018
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.