: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Core class that implements an file cache.
* The Object Cache stores all of the cache data to file and makes the cache
* contents available by using a file name as key, which is used to name and later retrieve
* @package ET\Core\Cache_File
class ET_Core_Cache_File {
protected static $_cache = array();
* Loaded cache file data.
protected static $_cache_loaded = array();
protected static $_dirty = array();
* Sets the data contents into the cache.
* @param string $cache_name What is the file name that storing the cache data.
* @param mixed $data The cache data to be set.
public static function set( $cache_name, $data ) {
if ( self::is_disabled() ) {
self::$_cache[ $cache_name ] = $data;
self::$_dirty[ $cache_name ] = $cache_name;
* Retrieves the cache contents, if it exists.
* @param string $cache_name What is the file name that storing the cache data.
public static function get( $cache_name ) {
if ( self::is_disabled() ) {
if ( ! isset( self::$_cache_loaded[ $cache_name ] ) ) {
$file = self::get_cache_file_name( $cache_name );
if ( et_()->WPFS()->is_readable( $file ) ) {
self::$_cache[ $cache_name ] = unserialize( et_()->WPFS()->get_contents( $file ) );
self::$_cache[ $cache_name ] = array();
self::$_cache_loaded[ $cache_name ] = true;
return isset( self::$_cache[ $cache_name ] ) ? self::$_cache[ $cache_name ] : array();
public static function save_cache() {
if ( self::is_disabled() || ! self::$_dirty || ! self::$_cache ) {
foreach ( self::$_dirty as $cache_name ) {
if ( ! isset( self::$_cache[ $cache_name ] ) ) {
$data = self::$_cache[ $cache_name ];
$file = self::get_cache_file_name( $cache_name );
if ( ! wp_is_writable( dirname( $file ) ) ) {
et_()->WPFS()->put_contents( $file, serialize( $data ) );
* Get full path of cache file name.
* The file name will be suffixed with .data
* @param string $cache_name What is the file name that storing the cache data.
public static function get_cache_file_name( $cache_name ) {
return sprintf( '%1$s/%2$s.data', ET_Core_PageResource::get_cache_directory(), $cache_name );
* Check is file based caching is disabled.
public static function is_disabled() {
return defined( 'ET_DISABLE_FILE_BASED_CACHE' ) && ET_DISABLE_FILE_BASED_CACHE;
// Hook the shutdown action once.
if ( ! has_action( 'shutdown', 'ET_Core_Cache_File::save_cache' ) ) {
add_action( 'shutdown', 'ET_Core_Cache_File::save_cache' );