Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
674 views
in Plugins by

Basically, I'm wonder what would be the sibling function to:

function qa_set_option($name$value$todatabase true) {...}

Something like this:

function qa_get_option($name$fromdatabase true) {...}

So basically I need to go dodge the cache, get to the database, fetch the value and then update the cache. How should I proceed in order to only fetch the given option and not the whole table?

Q2A version: 1.6.2
by
Am I missing something with your question? The qa_opt ()function gets or sets an option from the database. And the options are cached once retrieved.
by
edited by
The issue is that, due to another related question I've made (http://www.question2answer.org/qa/30898), I need to access the DB directly, avoiding the cache. So the cache will not be up-to-date with the data in the DB. So I need to hit the DB directly or, at least, refresh the cache. But I couldn't find a function that would allow me to get data directly from the DB and then update the cache (like the "fromdatabase = true" I mentioned in the question) only for a given option.

Another alternative would be to somehow invalidate the cache. I haven't seen anything related but I haven't looked for it. That might be useful too and extremely simple to implement as, I guess, it would only mean unsetting a value in the options array.

1 Answer

+1 vote
by
 
Best answer

The best solution I can think of does not use a magic core function but rather builds the SQL from scratch:

function getSettingFromDb($id) {
    return 
qa_db_read_one_value(qa_db_query_sub('
        SELECT content FROM ^options
        WHERE title = $'
, $idtrue));
}

Seems to be working fine. Note that if the cache differs (which is most likely, otherwise why would you be using such a function?) this will not update the cache.

...