[wp-hackers] Best Practices for Caching Plugin WidgetOutput?

Peter Westwood peter.westwood at ftwr.co.uk
Wed Dec 24 08:33:29 GMT 2008

Mike Schinkel wrote:
> Thanks Peter:
>> If your widget is configurable and supports multiple instances ensure that
> you key your cache based on the config data so that you have a cache entry
> per widget - something like naming the options mywidget_{md5($config_data)}
> I have two options: bycategory and bytag so I am using (something like)
> "mywidget-bycategory" and  "mywidget-bytag."   But I see you are using
> md5(); any reason why that would be a benefit?  It would seem to make it
> harder for me to look into the database and understand which option is which
> (I frequently look in the database during debugging to validate my coding
> assumptions.)
If you only have those two options then just having a 
mywidget-bycategory and mywidget-bytag is fine.

The idea behind using md5 is if your widget accepts a lot of config 
options you just md5 the string containing all the options and let that 
handle the matching for you.
>>> Invalidate the cache based on user-actions which require it to be
> invalidated - i.e. hook into the relevant actions for post <> category
> relationship updates
> Off hand, do you know which hooks those would be?
edit_post, save_post, wp_insert_post are all hooks that are fired on 
post updates and inserts.

You will need to decide which is the best to use (probably wp_insert_post).


Peter Westwood
http://blog.ftwr.co.uk | http://westi.wordpress.com
C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5 

More information about the wp-hackers mailing list