PluginProbe
ezCache / trunk
ezCache vtrunk
2.6.5 2.6.4 2.6.2 2.6.3 2.6.1 2.6.0 2.5.6 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5 2.2.1 2.2.2 trunk 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.3 1.3.1 1.3.10 1.3.11 All 49 releases
ezcache / includes / Rest / CacheController.php

CacheController.php in ezCache trunk, at includes/Rest/CacheController.php

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Restructure flat stats into nested format expected by Vue frontend
18 $structured_stats = [
19 'desktop' => [
20 'count' => $stats['desktop_count'] ?? 0,
21 'size' => $stats['desktop_size'] ?? 0,
22 ],
23 'mobile' => [
24 'count' => $stats['mobile_count'] ?? 0,
25 'size' => $stats['mobile_size'] ?? 0,
26 ],
27 'expired' => [
28 'count' => ( $stats['desktop_expired_count'] ?? 0 ) + ( $stats['mobile_expired_count'] ?? 0 ),
29 'size' => ( $stats['desktop_expired_size'] ?? 0 ) + ( $stats['mobile_expired_size'] ?? 0 ),
30 ],
31 'js' => [
32 'count' => $stats['js_count'] ?? 0,
33 'size' => $stats['js_size'] ?? 0,
34 ],
35 'css' => [
36 'count' => $stats['css_count'] ?? 0,
37 'size' => $stats['css_size'] ?? 0,
38 ],
39 'webp' => [
40 'count' => $stats['webp_images'] ?? 0,
41 'size' => $stats['webp_size'] ?? 0,
42 'original_size' => $stats['webp_original_size'] ?? 0,
43 ],
44 ];
45
46 return wp_send_json_success( [
47 'stats' => $structured_stats,
48 'notices' => [],
49 ] );
50 }
51
52 /**
53 * @param WP_REST_Request $request
54 */
55 function destroy( $request ) {
56 $input = $request->get_json_params();
57
58 Cache::instance()->clear_cache();
59
60 return wp_send_json_success( [ 'input' => $input ] );
61 }
62
63 }
64