| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/public_html/wp-content/plugins/tutor/cache/ |
Upload File : |
<?php
/**
* A run-time cache management for tutor.
*
* @package Tutor\Cache
* @author Themeum <support@themeum.com>
* @link https://themeum.com
* @since 2.1.9
*/
namespace Tutor\Cache;
/**
* TutorCache class
*
* @since 2.1.9
*/
final class TutorCache {
/**
* Store instance once and provide it for entire lifecycle
*
* @since 2.1.9
*
* @var self
*/
private static $instance = null;
/**
* Hold all run-time cache data.
*
* @since 2.1.9
*
* @var array
*/
private $data = array();
// Prevent to make instance
private function __construct(){}
// Prevent to clone instance
private function __clone(){}
/**
* Get the current class instance.
*
* @since 2.1.9
* @return self
*/
public static function getInstance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Check valid cache key.
*
* @since 2.1.9
*
* @param string $key cache key.
*
* @return boolean
*/
public function is_valid_key( $key ) {
if ( is_int( $key ) ) {
return true;
}
if ( is_string( $key ) && trim( $key ) !== '' ) {
return true;
}
return false;
}
/**
* Get cache data by key.
*
* @since 2.1.9
*
* @param string $key cache key.
* @param mixed $default default value if key does not exit.
*
* @return mixed
*/
public static function get( $key, $default = false ) {
$instance = self::getInstance();
if ( ! $instance->is_valid_key( $key ) ) {
return false;
}
if ( array_key_exists( $key, $instance->data ) ) {
return $instance->data[ $key ];
}
return $default;
}
/**
* Set cache data to a cache key.
*
* @since 2.1.9
*
* @param string $key cache key.
* @param mixed $value cache value.
*
* @return void
*/
public static function set( $key, $value ) {
$instance = self::getInstance();
if ( ! $instance->is_valid_key( $key ) ) {
return false;
}
$instance->data[ $key ] = $value;
}
/**
* Get all cached data.
*
* @since 2.1.9
*
* @return array
*/
public static function get_all() {
return self::getInstance()->data;
}
}