phpphpflickr

phpFlickr cache not updating when photo is deleted


I'm using phpFlickr on my website and the uploading/deletion works fine, but when I delete a photo and/or delete a photo from a photoset the cache (using the file system option) lags a few minutes behind and still shows the then-deleted image.

If I disable the cache it works as expected. Is there any way to manually purge the cache when performing a deletion?


Solution

  • Solution to remove a particular flickr set and all images associated with the set from the /path/to/phpFlickrCache directory. You'll need to supply the $flickr_photoset_id and filesystem path. All other sets and their images will remain in the cache.

    $flickrset = exec("grep -l '" . $flickr_photoset_id . "' /path/to/phpFlickrCache/*.cache");
    
    if ($f = fopen($flickrset, "r")) {
        $s = fgets($f, 24000);
        fclose($f);
        unlink($flickrset);
    
        preg_match_all("/\"id\";s:10:\"(\d+)\";/", $s, $images);
    
        // $images[1] contains matched images from (\d+)
        foreach ($images[1] as $img) {
            $i = exec("grep -l '" . $img . "' /path/to/phpFlickrCache/*.cache");
            unlink($i);
        }
    }