Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 2455

Extension Writers Discussion • Utilizing the cache for extension-specific data

$
0
0
I have a listener that on

Code:

'core.text_formatter_s9e_render_before'
needs to query the database looking for a particular entry. Specifically, it's checking for the existence of a file. I currently use `file_exists()` which is super fast. However, for various reasons, I'd like to check the database instead.

E.g. like this:

Code:

            $sql = 'SELECT 1 FROM phpbb3_external_images WHERE file = "' . $file_name"';            $result = $this->db->sql_query($sql);            $exists = $this->db->sql_fetchrow($result) ? true : false;            $this->db->sql_freeresult($result);
I've found this is super slow. It appears it's possible to use the built-in database cache system to cache this, but I can't figure out how to make it work.

The API document doesn't seem to provide any hints.

I'd like to do something like this (pseudo code):

Code:

        $cache_key = 'file_exists_' . $file_name . '_' . $file_ext;        $exists = $this->cache->get($cache_key);                if ($exists === false) {            $sql = 'SELECT 1 FROM phpbb3_external_images WHERE file = "' . $file_name . '" AND ext = "' . $file_ext . '"';            $result = $this->db->sql_query($sql);            $exists = $this->db->sql_fetchrow($result) ? true : false;            $this->db->sql_freeresult($result);            $this->cache->put($cache_key, $exists);        }        return $exists;
Is there an API in phpbb that will help with this?

Statistics: Posted by tig_ — Wed Jan 08, 2025 2:56 pm



Viewing all articles
Browse latest Browse all 2455

Trending Articles