src/Service/Cdn.php
protected function unsetCacheObject($object, $clearCacheDir = true)
    {
        $objectId       = isset($object->id) ? $object->id : '';
        $objectFilename = isset($object->file->name->disk) ? $object->file->name->disk : '';
        $bucketId       = isset($object->bucket->id) ? $object->bucket->id : '';
        $bucketSlug     = isset($object->bucket->slug) ? $object->bucket->slug : '';

        // --------------------------------------------------------------------------

        $this->unsetCache('object-' . $objectId);
        $this->unsetCache('object-' . $objectFilename);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketId);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketSlug);

        // --------------------------------------------------------------------------

        //  Clear out any cache files
        if ($clearCacheDir) {

            // Create a handler for the directory
            $pattern = '#^' . $bucketSlug . '-' . substr($objectFilename, 0, strrpos($objectFilename, '.')) . '#';
            $fh      = @opendir(static::CACHE_PATH);

            if ($fh !== false) {

                // Open directory and walk through the file names
                while ($file = readdir($fh)) {

                    // If file isn't this directory or its parent, add it to the results
                    if ($file != '.' && $file != '..') {

                        // Check with regex that the file format is what we're expecting and not something else
                        if (preg_match($pattern, $file) && file_exists(static::CACHE_PATH . $file)) {
                            unlink(static::CACHE_PATH . $file);
                        }
                    }
                }
            }
        }
    }
protected function unsetCacheObject($object, $clearCacheDir = true)
    {
        $objectId       = isset($object->id) ? $object->id : '';
        $objectFilename = isset($object->file->name->disk) ? $object->file->name->disk : '';
        $bucketId       = isset($object->bucket->id) ? $object->bucket->id : '';
        $bucketSlug     = isset($object->bucket->slug) ? $object->bucket->slug : '';

        // --------------------------------------------------------------------------

        $this->unsetCache('object-' . $objectId);
        $this->unsetCache('object-' . $objectFilename);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketId);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketSlug);

        // --------------------------------------------------------------------------

        //  Clear out any cache files
        if ($clearCacheDir) {

            // Create a handler for the directory
            $pattern = '#^' . $bucketSlug . '-' . substr($objectFilename, 0, strrpos($objectFilename, '.')) . '#';
            $fh      = @opendir(static::CACHE_PATH);

            if ($fh !== false) {

                // Open directory and walk through the file names
                while ($file = readdir($fh)) {

                    // If file isn't this directory or its parent, add it to the results
                    if ($file != '.' && $file != '..') {

                        // Check with regex that the file format is what we're expecting and not something else
                        if (preg_match($pattern, $file) && file_exists(static::CACHE_PATH . $file)) {
                            unlink(static::CACHE_PATH . $file);
                        }
                    }
                }
            }
        }
    }
protected function unsetCacheObject ( $ object , $ clearCacheDir = true ) { $ objectId = isset ( $ object -> id ) ? $ object -> id : '' ; $ objectFilename = isset ( $ object -> file -> name -> disk ) ? $ object -> file -> name -> disk : '' ; $ bucketId = isset ( $ object -> bucket -> id ) ? $ object -> bucket -> id : '' ; $ bucketSlug = isset ( $ object -> bucket -> slug ) ? $ object -> bucket -> slug : '' ; // -------------------------------------------------------------------------- $ this -> unsetCache ( 'object-' . $ objectId ) ; $ this -> unsetCache ( 'object-' . $ objectFilename ) ; $ this -> unsetCache ( 'object-' . $ objectFilename . '-' . $ bucketId ) ; $ this -> unsetCache ( 'object-' . $ objectFilename . '-' . $ bucketSlug ) ; // -------------------------------------------------------------------------- //  Clear out any cache files if ( $ clearCacheDir ) { // Create a handler for the directory $ pattern = '#^' . $ bucketSlug . '-' . substr ( $ objectFilename , 0 , strrpos ( $ objectFilename , '.' ) ) . '#' ; $ fh = @ opendir ( static :: CACHE_PATH ) ; if ( $ fh !== false ) { // Open directory and walk through the file names while ( $ file = readdir ( $ fh ) ) { // If file isn't this directory or its parent, add it to the results if ( $ file != '.' && $ file != '..' ) { // Check with regex that the file format is what we're expecting and not something else if ( preg_match ( $ pattern , $ file ) && file_exists ( static :: CACHE_PATH . $ file ) ) { unlink ( static :: CACHE_PATH . $ file ) ; } } } } } }
Unset an object from the cache in one fell swoop

@param \stdClass $object        The object to remove from the cache
@param bool      $clearCacheDir Whether to clear the cache directory or not
Unset an object from the cache in one fell swoop