annotate core/lib/Drupal/Component/Utility/OpCodeCache.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Component\Utility;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Provides helpers to handle PHP opcode caches.
Chris@0 7 *
Chris@0 8 * @ingroup utility
Chris@0 9 */
Chris@0 10 class OpCodeCache {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Checks if OpCodeCache is enabled.
Chris@0 14 *
Chris@0 15 * @return bool
Chris@0 16 * TRUE if opcache is enabled, FALSE otherwise.
Chris@0 17 */
Chris@0 18 public static function isEnabled() {
Chris@0 19 return extension_loaded('Zend OPcache') && ini_get('opcache.enable');
Chris@0 20 }
Chris@0 21
Chris@0 22 /**
Chris@0 23 * Invalidates a PHP file from a possibly active opcode cache.
Chris@0 24 *
Chris@0 25 * In case the opcode cache does not support to invalidate an individual file,
Chris@0 26 * the entire cache will be flushed.
Chris@0 27 *
Chris@0 28 * @param string $pathname
Chris@0 29 * The absolute pathname of the PHP file to invalidate.
Chris@0 30 */
Chris@0 31 public static function invalidate($pathname) {
Chris@0 32 clearstatcache(TRUE, $pathname);
Chris@0 33
Chris@0 34 // Check if the Zend OPcache is enabled and if so invalidate the file.
Chris@0 35 if (function_exists('opcache_invalidate')) {
Chris@0 36 opcache_invalidate($pathname, TRUE);
Chris@0 37 }
Chris@0 38 }
Chris@0 39
Chris@0 40 }