| @@ -32,9 +32,14 @@ | ||
| 32 | 32 | * Set/Update will check key from table thim_cache |
| 33 | 33 | * else only WP Cache |
| 34 | 34 | */ |
| 35 | 35 | public function __construct( $has_thim_cache = false ) { |
| 36 | - $this->key_group = $this->key_group_parent . '/' . $this->key_group_child; | |
| 36 | + $this->key_group = $this->key_group_parent; | |
| 37 | + | |
| 38 | + if ( ! empty( $this->key_group_child ) ) { | |
| 39 | + $this->key_group .= '/' . $this->key_group_child; | |
| 40 | + } | |
| 41 | + | |
| 37 | 42 | $this->has_thim_cache = $has_thim_cache; |
| 38 | 43 | } |
| 39 | 44 | |
| 40 | 45 | /** |
| @@ -53,12 +58,18 @@ | ||
| 53 | 58 | wp_cache_set( $key, $data, $this->key_group, $expire ); |
| 54 | 59 | // Cache thim_cache |
| 55 | 60 | if ( $this->can_handle_with_thim_cache() ) { |
| 56 | 61 | $key = "{$this->key_group}/{$key}"; |
| 57 | - Thim_Cache_DB::instance()->set_value( $key, $data, $expire ); | |
| 62 | + | |
| 63 | + if ( ! is_string( $data ) ) { | |
| 64 | + $data = wp_json_encode( $data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + $expiration = $expire > 0 ? time() + $expire : 0; | |
| 68 | + Thim_Cache_DB::instance()->set_value( $key, $data, $expiration ); | |
| 58 | 69 | } |
| 59 | 70 | } catch ( Throwable $e ) { |
| 60 | - error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 71 | + LP_Debug::error_log( $e ); | |
| 61 | 72 | } |
| 62 | 73 | } |
| 63 | 74 | |
| 64 | 75 | /** |
| @@ -73,11 +84,12 @@ | ||
| 73 | 84 | // Get thim_cache |
| 74 | 85 | if ( false === $cache && $this->can_handle_with_thim_cache() ) { |
| 75 | 86 | $key = "{$this->key_group}/{$key}"; |
| 76 | 87 | $cache = Thim_Cache_DB::instance()->get_value( $key ); |
| 77 | - /*if ( is_string( $cache ) ) { | |
| 78 | - $cache = wp_unslash( $cache ); | |
| 79 | - }*/ | |
| 88 | + try { | |
| 89 | + $cache = LP_Helper::json_decode( $cache, true ); | |
| 90 | + } catch ( Throwable $e ) { | |
| 91 | + } | |
| 80 | 92 | } |
| 81 | 93 | |
| 82 | 94 | return $cache; |
| 83 | 95 | } |