Small question about cache variable
#1

Hi,

I've been using the cache variable like this whenever i need to fetch the result from the db.

PHP Code:
IRCCMD:setofflevel(botidchannel[], user[], host[], params[]) {
    if(
IRC_IsOp(botidchanneluser)) {
        new 
lvl;
        if(
sscanf(params"s[24]i"paramslvl)) return IRC_GroupSay(groupIDIRC_CHANNEL"4[Error] Use: !setofflevel <username> <level>");
        if(
lvl 6) return IRC_GroupSay(groupIDIRC_CHANNEL"4[Error] Invalid level.");
        if(
isuseronline(params))
            return 
IRC_GroupSay(groupIDIRC_CHANNEL"4[Error] This user is currently online.");
          new 
Cache:result;
        
Query("SELECT `nick` FROM `users` WHERE `nick`='%e' ORDER BY `id`"params);
        
result mysql_query(mysqlquery);
        if(!
cache_get_row_count()) {
            
IRC_GroupSay(groupIDIRC_CHANNEL"4[Error] The account with this username doesn't exist.");
               
cache_delete(result);
               return 
1;
          }
        new 
tmplvl cache_get_field_content_int(0"level");
        if(
lvl == tmplvl) {
            
IRC_GroupSay(groupIDIRC_CHANNEL"4[Error] This user already has that level.");
            
cache_delete(result);
            return 
1;
        }
        if(
lvl tmplvl || lvl tmplvl)
        {
            new 
id cache_get_field_content_int(0"id"), string[100];
            
Query("UPDATE `users` SET `level`='%i' WHERE `id`='%i'"lvlid);
            
mysql_tquery(mysqlquery"QueryExecute""i"result_none);
            
format:string("3[Info] You have set %s's admin level to %i"paramslvl);
            
IRC_GroupSay(groupIDIRC_CHANNELstring);
        }
        
cache_delete(result);
    }
    return 
1;

I want to know if the way I am doing it is right or not? If someone can explain me about how to use it and how it functions, I'd be thankful.
Reply
#2

Why would you cache it? Do you really want to use it all in one single command without multi-threading your queries? If that's really necessary for you, then use y_inline library from YSF or just create a public for SELECT queries. If you need to understand threaded queries, then ****** it and find out everything you need. It is recommended to DO NOT do it your way.
Reply
#3

Quote:
Originally Posted by Riddick94
View Post
Why would you cache it? Do you really want to use it all in one single command without multi-threading your queries? If that's really necessary for you, then use y_inline library from YSF or just create a public for SELECT queries. If you need to understand threaded queries, then ****** it and find out everything you need. It is recommended to DO NOT do it your way.
Well, as I said I don't know how this works that's why I am asking here, the reason why I am using it is because, according to wiki about mysql_query I saw this

Quote:

It's highly recommended to thread all your queries (even INSERT & UPDATE).
Use cache_delete() if you don't need the query's result anymore or you will experience memory leaks.

All I want is, simply get a result from the db and utilize them. If cache is not necessary for this purpose, should I set use_cache to false with mysql_query function?

I am still pretty confused with it, I'd appreciate if you can explain me tad more.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)