2020-09-11 13:38:02 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Manages caching of values.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\ApiClient\Helper
|
2020-09-11 13:38:02 +03:00
|
|
|
*/
|
2020-09-11 14:24:08 +03:00
|
|
|
|
2020-09-11 13:38:02 +03:00
|
|
|
declare( strict_types=1 );
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
|
2020-09-11 13:38:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Cache
|
|
|
|
*/
|
|
|
|
class Cache {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The prefix for the value keys.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $prefix;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache constructor.
|
|
|
|
*
|
2020-09-11 14:24:08 +03:00
|
|
|
* @param string $prefix The prefix for the value keys.
|
2020-09-11 13:38:02 +03:00
|
|
|
*/
|
2020-09-11 14:24:08 +03:00
|
|
|
public function __construct( string $prefix ) {
|
2020-09-11 13:38:02 +03:00
|
|
|
$this->prefix = $prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a value.
|
|
|
|
*
|
|
|
|
* @param string $key The key under which the value is stored.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-09-11 14:24:08 +03:00
|
|
|
public function get( string $key ) {
|
|
|
|
return get_transient( $this->prefix . $key );
|
2020-09-11 13:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches a value.
|
|
|
|
*
|
|
|
|
* @param string $key The key under which the value should be cached.
|
2020-09-11 14:24:08 +03:00
|
|
|
* @param mixed $value The value to cache.
|
2020-09-11 13:38:02 +03:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2020-09-11 14:24:08 +03:00
|
|
|
public function set( string $key, $value ): bool {
|
|
|
|
return (bool) set_transient( $this->prefix . $key, $value );
|
2020-09-11 13:38:02 +03:00
|
|
|
}
|
2020-09-11 14:24:08 +03:00
|
|
|
}
|