[wp-hackers] another cache?

David House dave at xmouse.ithium.net
Sun Oct 17 09:14:54 UTC 2004


Hi all,
I'm trying to introduce more caching into my code, and I think $cache_categories
is certainly one variable that I could use more. However, the problem is that
I'm using the nice URIs, and so I don't have access to the cat_ID (without
querying, which kind of defeats the object) which $cache_categories is indexed
by. Hence, I'm finding it very difficult to replace calls like

$wpdb->get_var('SELECT cat_name FROM ' . $wpdb->categories . ' WHERE
category_nicename=\'' . get_query_var('category_nicename') . '\'');

with something cached. Possible solutions:

* re-index $cache_categories by category_nicename (not good: kills any code
currently using cache)
* make another cache which is indexed by category_nicename and holds the cat_ID
of each category. (better, doesn't kill current code but isn't very flexible)
* make a function that searches through $cache_categories and returns the
category with that specific column value (eg, you could pass it a
category_nicename and it would the details of the category with that
category_nicename, or you could pass it a category_description or a
cat_name...) (better, introduces some overhead, but is very flexible. We may
have problems when more than one category share the same category_nicename, eg
categories called 'category1@' and 'category1#', which both get sanitized to
'category1'.

All three of these solutions would be fairly easy to implement. Which do you
think would be the best option?

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the hackers mailing list