Limit queries for pulling add-on options?

CaseLogic

New member
I am working on an add-on, and I have set up an option for it in the admincp. However I quickly noticed that these options don't seem to be cached. I have overloaded two model functions, and in each one I am grabbing this option I have set up. When I run the page, I see that my db queries has increased by 2, one for each of the option queries.

I figured that the options would be cached somewhere so it wouldn't use up a db query to grab it. Do you guys have any recommendations for how I can store this value so it doesn't need to query each time? Can I add it to a global registry or something the first time I grab it and then just check that in the future? What have you guys been doing? Maybe I'm just approaching this the wrong way.
 
I am working on an add-on, and I have set up an option for it in the admincp. However I quickly noticed that these options don't seem to be cached. I have overloaded two model functions, and in each one I am grabbing this option I have set up. When I run the page, I see that my db queries has increased by 2, one for each of the option queries.

I figured that the options would be cached somewhere so it wouldn't use up a db query to grab it. Do you guys have any recommendations for how I can store this value so it doesn't need to query each time? Can I add it to a global registry or something the first time I grab it and then just check that in the future? What have you guys been doing? Maybe I'm just approaching this the wrong way.

Check your debug page. There you'll probably see the 2 new queries. Are they really because of the options?
Do you use probably custom templates? Or do you do anything else inside the 2 model functions?
 
Thanks for the responses. I'm modifying the content that gets displayed on the forum view. I have overloaded 2 thread model functions so it changes the conditions of the threads it pulls depending on the set option. I have overloaded the countThreadsInForum routine and the getThreadsInForum routine. The only thing that these routines are doing is pulling the option using the Application::getOption('options') call and modifying the conditions. Then it passes on to the next function as usual. So the only thing in these routines that would generate 2 new db queries is the getOption call.

Jake, I have set up the options via that page. I added a new option group/option for my addon, and am getting the option via the $options = getOption('options'); $myoption = $options['myoption'] method that I saw in a tutorial somewhere.
 
Top Bottom