Back to File class

Method invalidateFileCache

public static bool
invalidateFileCache
(mixed $filepath, mixed $force = true)
Invalidate opcache for a newly written/deleted file immediately, if opcache* functions exist and if this was a PHP file.
Parameters
  • string $filepath The path to the file just written to, to flush from opcache
  • bool $force If set to true, the script will be invalidated regardless of whether invalidation is necessary
Returns
  • bool TRUE if the opcode cache for script was invalidated/nothing to invalidate, or FALSE if the opcode cache is disabled or other conditions returning FALSE from opcache_invalidate (like file not found).
Since
  • 4.0.1
Class: File
Project: Joomla

Method invalidateFileCache - Source code

/**
 * Invalidate opcache for a newly written/deleted file immediately, if opcache* functions exist and if this was a PHP file.
 *
 * @param   string  $filepath   The path to the file just written to, to flush from opcache
 * @param   boolean $force      If set to true, the script will be invalidated regardless of whether invalidation is necessary
 *
 * @return boolean TRUE if the opcode cache for script was invalidated/nothing to invalidate,
 *                 or FALSE if the opcode cache is disabled or other conditions returning
 *                 FALSE from opcache_invalidate (like file not found).
 *
 * @since 4.0.1
 */
public static function invalidateFileCache($filepath, $force = true)
{
    if (self::canFlushFileCache() && '.php' === strtolower(substr($filepath, -4))) {
        return opcache_invalidate($filepath, $force);
    }
    return false;
}