How can I programmatically flush Magento's Cache?

If you really wanted to you could also clean just one or more cache types. This is actually how the admin section does it. Under Mage_Adminhtml_CacheController::massRefreshAction

You can see that it loops through all the parameters types and calls the following

$tags = Mage::app()->getCacheInstance()->cleanType($type);
Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $type));
$updatedTypes++;

Possible types are as follows:

  1. config
  2. layout
  3. block_html
  4. translate
  5. collections
  6. eav
  7. config_api
  8. config_api2
  9. full_page

And these can be returned by calling Mage::app()->getCacheInstance()->getTypes()


Please try the following code to flush the cache programatically

Mage::app()->cleanCache()

or

Mage::app()->getCacheInstance()->flush(); 

A quick external script to clear all cache:

<?php

require_once './app/Mage.php';
umask(0);
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

try {
    $allTypes = Mage::app()->useCache();
    foreach($allTypes as $type => $value) {
        Mage::app()->getCacheInstance()->cleanType($type);
        Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $type));
        echo "{$type} </br>";
    }
    echo 'done';
} catch (Exception $e) {
    echo $e->getMessage();
}