[wp-hackers] Confusion About WordPress Cache
Brian Layman
bulk at thecodecave.com
Fri Dec 17 15:33:17 UTC 2010
On 12/17/2010 9:57 AM, Otto wrote:
> For this reason, the
> object cache should be treated as if it's (unreliable) persistent
> storage even when it's not that way by default.
Unreliable - in that it should only be used for short to medium term
storage as the data goes away when the daemon or machine restarts. So
your retrieval of values should always fall back to generating the values.
So in psuedocode, you'd have something like this:
if (!$value = retrievefunction($networkid . '_' . $blogid .
'_variablename')) {
long();
drawnout();
generation();
$value = finalprocessing();
}
Obviously that will look nothing like your final code, but I wanted to
show that the actually value you store will, as with any global
variable, needs to have a unique name or it will be overwritten.
So, in a multisite environment, you should store your values under names
that specify their scope. So, something that is global to all your
networks needs to have nothing or perhaps a standardized 'global_'
prefix. If it is for all sites on one network, prefix it with the
network id. If it is specific to a site on a network, prefix it with the
network AND site id.
Even in a single site blog, setting up your cache names correctly now
will save you headaches when 2 years down the line you decide to merge
two blogs together or move your theme over to a multisite blog.
-Brian
More information about the wp-hackers
mailing list