| 1 |
<?php |
| 2 |
namespace Upress\EzCache\Rest; |
| 3 |
|
| 4 |
use Exception; |
| 5 |
use Upress\EzCache\Cache; |
| 6 |
use WP_REST_Request; |
| 7 |
|
| 8 |
class CacheController { |
| 9 |
|
| 10 |
function show() { |
| 11 |
try { |
| 12 |
$stats = Cache::instance()->get_cache_stats(); |
| 13 |
} catch( Exception $ex) { |
| 14 |
return wp_send_json_error( [ 'error' => $ex->getMessage() ] ); |
| 15 |
} |
| 16 |
|
| 17 |
return wp_send_json_success( $stats ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @param WP_REST_Request $request |
| 22 |
*/ |
| 23 |
function destroy( $request ) { |
| 24 |
$input = $request->get_json_params(); |
| 25 |
|
| 26 |
Cache::instance()->clear_cache(); |
| 27 |
|
| 28 |
return wp_send_json_success( [ 'input' => $input ] ); |
| 29 |
} |
| 30 |
|
| 31 |
} |
| 32 |
|