A small code snippet that allows you to accomplish this functionality it is presented below:

try {
    $cacheTypes = Mage::app()->useCache();
    foreach ($cacheTypes as $type => $option) {
        Mage::app()->getCacheInstance()->cleanType($type);
        //echo $type . ' Successfully Cleared ';
    }
} catch (Exception $e) {
    Mage::log($e->getMessage());
}

 

To refresh the images cache you can use the following snippet:

try {
    Mage :: getModel('catalog/product_image')->clearCache();
    //echo 'Image cache was cleared successfully';
} catch (Exception $e) {
    Mage::log($e->getMessage());
}

 

Have fun coding ;)