php - Empty image cache for specific product in Magento 1.8? -


i have custom module in magento automatically updates product images ftp directory. when product updated new image need manually flush catalog image cache display new image on frontend. however, clears image cache , library of several thousand products it's not option.

is possible clear image cache specific product in php?

unfortunately magento (afaik) not provide native function that. on *nix can use shell search through cache folder (lowercase) sku , delete those.

please note php need right execute shell commands code below work. after calling ::findcacheimages can iterate through result , delete cached images.

example 1 of classes:

/**  * array of files in image cache tree. provide sku @ once better performance.  *  * @param array $skus  * @return array  */ static public function findcacheimages(array $skus) {     if (!$skus) {         return array();     }     $skus     = array_unique($skus);     $tosearch = array();     $result   = array();     while (count($skus) > 0) {         $sku = array_pop($skus);         if (trim($sku) != '') {             $tosearch[] = $sku;         }         if (count($tosearch) > 50 || count($skus) == 0) {             // perform file search             $bigregex = array();             foreach ($tosearch $fname) {                 // build regex                 $bigregex[] = '.*/' . strtolower($fname) . '.*';             }             $bigregexstr = implode('|', $bigregex);             $dir         = escapeshellcmd(mage::getbasedir() . '/media/catalog/product/cache/');             $result      = array_merge(self::findfilesregex($dir, $bigregexstr), $result);             $tosearch    = array();         }     }     return $result; }  /**  * @param string $dir  * @param string $regex  * @return array  */ static public function findfilesregex($dir, $regex) {     $files = shell_exec("find $dir -type f -regextype posix-extended -regex '$regex' -print");     $files = explode("\n", trim($files));     return $files; } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -