| @@ -16,8 +16,16 @@ | ||
| 16 | 16 | $this->get( $this->endpoint, [ $this, 'get_categories' ] ); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function get_categories() { |
| 20 | + /** | |
| 21 | + * Return if there is any cache data. | |
| 22 | + */ | |
| 23 | + $types = Database::get_transient( $this->endpoint ); | |
| 24 | + if( ! empty( $types ) ){ | |
| 25 | + return $this->success( $types ); | |
| 26 | + } | |
| 27 | + | |
| 20 | 28 | /** @noinspection SpellCheckingInspection */ |
| 21 | 29 | $id = $this->get_param( 'id', 0, 'intval' ); |
| 22 | 30 | $funcArgs = []; |
| 23 | 31 | |
| @@ -24,26 +32,15 @@ | ||
| 24 | 32 | if ( $id > 0 ) { |
| 25 | 33 | $funcArgs['id'] = $id; |
| 26 | 34 | } |
| 27 | 35 | |
| 28 | - $fields = 'id, name, slug, status, packs_count'; | |
| 29 | - $transient_key = $this->endpoint . '_' . md5( $fields . json_encode( $funcArgs ) ); | |
| 30 | - | |
| 36 | + $response = $this->http()->query( $this->endpoint, 'id, name, slug, status', $funcArgs )->post(); | |
| 31 | 37 | /** |
| 32 | - * Return if there is any cache data. | |
| 33 | - */ | |
| 34 | - $types = Database::get_transient( $transient_key ); | |
| 35 | - if( ! empty( $types ) ){ | |
| 36 | - return $this->success( $types ); | |
| 37 | - } | |
| 38 | - | |
| 39 | - $response = $this->http()->query( $this->endpoint, $fields, $funcArgs )->post(); | |
| 40 | - /** | |
| 41 | 38 | * Caching the response in transient. |
| 42 | 39 | */ |
| 43 | 40 | if( ! is_wp_error( $response ) ) { |
| 44 | - Database::set_transient( $transient_key, $response ); | |
| 41 | + Database::set_transient( $this->endpoint, $response ); | |
| 45 | 42 | } |
| 46 | 43 | |
| 47 | 44 | return $response; |
| 48 | 45 | } |
| 49 | 46 | } |