: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
if ( ! defined( 'ABSPATH' ) ) {
* @var FS_Cache_Manager[]
private static $_MANAGERS = array();
* @author Vova Feldman (@svovaf)
private function __construct( $id ) {
$this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
$this->_logger->entrance();
$this->_logger->log( 'id = ' . $id );
$this->_options = FS_Option_Manager::get_manager( $id, true, true, false );
* @author Vova Feldman (@svovaf)
* @return FS_Cache_Manager
static function get_manager( $id ) {
if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
return self::$_MANAGERS[ $id ];
* @author Vova Feldman (@svovaf)
$this->_logger->entrance();
return $this->_options->is_empty();
* @author Vova Feldman (@svovaf)
$this->_logger->entrance();
$this->_options->clear( true );
* Delete cache manager from DB.
* @author Vova Feldman (@svovaf)
$this->_options->delete();
* Check if there's a cached item.
* @author Vova Feldman (@svovaf)
$cache_entry = $this->_options->get_option( $key, false );
return ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
* Check if there's a valid cached item.
* @author Vova Feldman (@svovaf)
* @param null|int $expiration Since 1.2.2.7
function has_valid( $key, $expiration = null ) {
$cache_entry = $this->_options->get_option( $key, false );
$is_valid = ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
is_numeric( $expiration ) &&
isset( $cache_entry->created ) &&
is_numeric( $cache_entry->created ) &&
$cache_entry->created + $expiration < WP_FS__SCRIPT_START_TIME
* Even if the cache is still valid, since we are checking for validity
* with an explicit expiration period, if the period has past, return
* `false` as if the cache is invalid.
* @author Vova Feldman (@svovaf)
function get( $key, $default = null ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
return $cache_entry->result;
return is_object( $default ) ? clone $default : $default;
* @author Vova Feldman (@svovaf)
function get_valid( $key, $default = null ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
return $cache_entry->result;
return is_object( $default ) ? clone $default : $default;
* @author Vova Feldman (@svovaf)
* @param int $created Since 2.0.0 Cache creation date.
function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC, $created = WP_FS__SCRIPT_START_TIME ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = new stdClass();
$cache_entry->result = $value;
$cache_entry->created = $created;
$cache_entry->timestamp = $created + $expiration;
$this->_options->set_option( $key, $cache_entry, true );
* Get cached record expiration, or false if not cached or expired.
* @author Vova Feldman (@svovaf)
function get_record_expiration( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp ) &&
$cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
return $cache_entry->timestamp;
* @author Vova Feldman (@svovaf)
$this->_logger->entrance( 'key = ' . $key );
$this->_options->unset_option( $key, true );
* Extend cached item caching period.
* @author Vova Feldman (@svovaf)
function update_expiration( $key, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( ! is_object( $cache_entry ) ||
! isset( $cache_entry->timestamp ) ||
! is_numeric( $cache_entry->timestamp )
$this->set( $key, $cache_entry->result, $expiration, $cache_entry->created );
* Set cached item as expired.
* @author Vova Feldman (@svovaf)
function expire( $key ) {
$this->_logger->entrance( 'key = ' . $key );
$cache_entry = $this->_options->get_option( $key, false );
if ( is_object( $cache_entry ) &&
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
$cache_entry->timestamp = WP_FS__SCRIPT_START_TIME;
$this->_options->set_option( $key, $cache_entry, true );
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
* Migrate options from site level.
* @author Vova Feldman (@svovaf)
function migrate_to_network() {
$this->_options->migrate_to_network();