[], self::CACHE_IN_MEMORY_GZIP => [], self::CACHE_IN_MEMORY_SERIALIZED => [], self::CACHE_IGBINARY => [], self::CACHE_TO_PHPTEMP => [ 'memoryCacheSize' => '1MB', ], self::CACHE_TO_DISCISAM => [ 'dir' => null, ], self::CACHE_TO_APC => [ 'cacheTime' => 600, ], self::CACHE_TO_MEMCACHE => [ 'memcacheServer' => 'localhost', 'memcachePort' => 11211, 'cacheTime' => 600, ], self::CACHE_TO_WINCACHE => [ 'cacheTime' => 600, ], self::CACHE_TO_SQLITE => [], self::CACHE_TO_SQLITE3 => [], ]; /** * Arguments for the active cache storage method. * * @var mixed[] */ private static $storageMethodParameters = []; /** * Return the current cache storage method. * * @return string|null **/ public static function getCacheStorageMethod() { return self::$cacheStorageMethod; } /** * Return the current cache storage class. * * @return string **/ public static function getCacheStorageClass() { return self::$cacheStorageClass; } /** * Return the list of all possible cache storage methods. * * @return string[] **/ public static function getAllCacheStorageMethods() { return self::$storageMethods; } /** * Return the list of all available cache storage methods. * * @return string[] **/ public static function getCacheStorageMethods() { $activeMethods = []; foreach (self::$storageMethods as $storageMethod) { $cacheStorageClass = '\\PhpOffice\\PhpSpreadsheet\\CachedObjectStorage\\' . $storageMethod; if (call_user_func([$cacheStorageClass, 'cacheMethodIsAvailable'])) { $activeMethods[] = $storageMethod; } } return $activeMethods; } /** * Identify the cache storage method to use. * * @param string $method Name of the method to use for cell cacheing * @param mixed[] $arguments Additional arguments to pass to the cell caching class * when instantiating * * @return bool **/ public static function initialize($method = self::CACHE_IN_MEMORY, $arguments = []) { if (!in_array($method, self::$storageMethods)) { return false; } $cacheStorageClass = '\\PhpOffice\\PhpSpreadsheet\\CachedObjectStorage\\' . $method; if (!call_user_func([$cacheStorageClass, 'cacheMethodIsAvailable'])) { return false; } self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method]; foreach ($arguments as $argument => $value) { if (isset(self::$storageMethodParameters[$method][$argument])) { self::$storageMethodParameters[$method][$argument] = $value; } } if (self::$cacheStorageMethod === null) { self::$cacheStorageClass = '\\PhpOffice\\PhpSpreadsheet\\CachedObjectStorage\\' . $method; self::$cacheStorageMethod = $method; } return true; } /** * Initialise the cache storage. * * @param Worksheet $parent Enable cell caching for this worksheet * * @return CachedObjectStorage\ICache **/ public static function getInstance(Worksheet $parent) { $cacheMethodIsAvailable = true; if (self::$cacheStorageMethod === null) { $cacheMethodIsAvailable = self::initialize(); } if ($cacheMethodIsAvailable) { $instance = new self::$cacheStorageClass( $parent, self::$storageMethodParameters[self::$cacheStorageMethod] ); if ($instance !== null) { return $instance; } } return false; } /** * Clear the cache storage. **/ public static function finalize() { self::$cacheStorageMethod = null; self::$cacheStorageClass = null; self::$storageMethodParameters = []; } }