1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
<?php
namespace VSP;
defined( 'ABSPATH' ) || exit;
/**
* Class Cache
*
* @package VSP\Core\Abstracts
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
class Cache {
/**
* Cache Key Prefix.
*
* @var string
*/
protected static $prefix = 'vsp';
/**
* Handles Cache Key System.
*
* @param $key
*
* @return string
*/
protected static function cache_key( $key ) {
return ( ! empty( static::$prefix ) ) ? static::$prefix . '/' . $key : $key;
}
/**
* Set Data Cache For Given Cache ID
*
* @param string $key cache_id.
* @param mixed $value
*
* @return mixed
*/
public static function set( $key, $value ) {
return wponion_set_cache( static::cache_key( $key ), $value );
}
/**
* Set Cache With Defaults.
*
* @param string $key cache_id.
* @param mixed $defaults
*
* @return bool|mixed
*/
public static function get_defaults( $key, $defaults = false ) {
return wponion_get_cache_defaults( self::cache_key( $key ), $defaults );
}
/**
* Fetch & Returns Cached Data.
*
* @param string $key cache_id.
*
* @return mixed
* @throws \WPOnion\Exception\Cache_Not_Found
*/
public static function get( $key ) {
return wponion_get_cache( self::cache_key( $key ) );
}
/**
* Deletes Cached Data For Given Key.
*
* @param string $key cache_id.
*/
public static function delete( $key ) {
wponion_delete_cache( self::cache_key( $key ) );
}
}