first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\TM\ATE\API\CacheStorage;
|
||||
|
||||
use WPML\FP\Obj;
|
||||
|
||||
class StaticVariable implements Storage {
|
||||
/** @var array */
|
||||
private static $cache = [];
|
||||
|
||||
/** @var self */
|
||||
private static $instance;
|
||||
|
||||
public static function getInstance() {
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $key, $default = null ) {
|
||||
return Obj::propOr( $default, $key, self::$cache );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function save( $key, $value ) {
|
||||
self::$cache[ $key ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*/
|
||||
public function delete( $key ) {
|
||||
self::$cache = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\TM\ATE\API\CacheStorage;
|
||||
|
||||
interface Storage {
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $key, $default = null );
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function save( $key, $value );
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*/
|
||||
public function delete( $key );
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\TM\ATE\API\CacheStorage;
|
||||
|
||||
use WPML\LIB\WP\Transient as WPTransient;
|
||||
|
||||
class Transient implements Storage {
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $key, $default = null ) {
|
||||
return WPTransient::getOr( $key, $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function save( $key, $value ) {
|
||||
WPTransient::set( $key, $value, 3600 * 24 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*/
|
||||
public function delete( $key ) {
|
||||
WPTransient::delete( $key );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user