Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a WP-site with not that many writes, but quite a few reads and a few specific hotspots in the templates that I'd like to cache pretty aggressively with my own PHP-caching mechanism.

I could implement this with a time-based cache expiration scheme, but as I'm sure Wordpress provides all the API I need for listening to different events, I could also hook into them for info on when I need to clear caches.

So, I'm a bit lost on the whole hooks / filters -thingy of Wordpress. I can add listeners to hooks easily enough, but I'm just a bit too overwhelmed with the amount of hooks available, so my question is:

What hooks should I hook into to basically be able to execute a script upon every INSERT / UPDATE / DELETE operation on the posts-table?

Any pointers on the way onward are much appreciated!

share|improve this question
    
Hooking into every single query would likely be massive waste of resources. Could you specify more clearly what exactly do you want to trigger cache cleanup? –  Rarst Apr 1 '11 at 0:05
    
Probably yes, but the again, the content on our site is not not updated that often and I only want the cache to be cleared when posts are updated, deleted or added. –  Tommi Forsström Apr 2 '11 at 6:37
add comment

3 Answers 3

While I understand it's not really the answer to your question, it might give your inspiration on how someone else did it: Clear W3C Total Cache

share|improve this answer
    
Actually, this did not answer my question, but did solve my problem! With the info in that question, I'm able to tweak W3 to my needs instead of using my own. –  Tommi Forsström Apr 2 '11 at 6:40
add comment

I only want the cache to be cleared when posts are updated, deleted or added

No need to mess with SQL for this. WordPress has dynamic (formed from variables rather than hardcoded) hooks for changes in post status. See Post Status Transitions in Codex.

With these you can precisely hook to post of specific type changing to specific status.

share|improve this answer
add comment

I have written a post on my blog which directly answers this topic. My post covers in detail, how to install the code, how to use the code, and what the code does.

If you read my blog post, you will be able to easily, automatically clear caches on the WordPress action hook: save_post, from the WordPress plugin: W3 Total Cache.

Automatically clear all caches with W3 Total Cache

You have the following options for which caches to clear upon the WordPress action hook save_post:

$this->clear_db_caches();
    Calls the W3TC function: w3tc_dbcache_flush();
    Clears the DB caches completely. Note: Doesn’t clear MySQL Query Cache, just WP based DB caches.
$this->clear_minify_caches();
    Calls the W3TC function: w3tc_minify_flush();
    Clears the minified content caches completely.
$this->clear_object_caches();
    Calls the W3TC function: w3tc_objectcache_flush();
    Clears the object caches completely.
$this->clear_page_caches();
    Calls the W3TC function: w3tc_pgcache_flush();
    Clears the Page Cache completely.
$this->clear_all_caches();
    Calls each of the W3TC functions in one instance.
    Attempts to clear all W3TC caches completely.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.