| @@ -13,24 +13,33 @@ | ||
| 13 | 13 | |
| 14 | 14 | $this->prefix = !empty($config['prefix']) ? $config['prefix'] : ''; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public function set($key, $val, $expiration = YEAR_IN_SECONDS) { | |
| 17 | + public function set($key, $val, $expiration = YEAR_IN_SECONDS): bool | |
| 18 | + { | |
| 18 | 19 | |
| 19 | 20 | return set_transient( $this->prefix.$key, $val, $expiration ); |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | - public function get($key) { | |
| 23 | + public function get($key, $default = null) { | |
| 23 | 24 | |
| 24 | - return get_transient( $this->prefix.$key ); | |
| 25 | + $value = get_transient( $this->prefix.$key ); | |
| 26 | + | |
| 27 | + if($value === false) { | |
| 28 | + return $default; | |
| 29 | + } | |
| 30 | + | |
| 31 | + return $value; | |
| 25 | 32 | } |
| 26 | 33 | |
| 27 | - public function delete($key) { | |
| 34 | + public function delete($key): bool | |
| 35 | + { | |
| 28 | 36 | |
| 29 | 37 | return delete_transient( $this->prefix.$key ); |
| 30 | 38 | } |
| 31 | 39 | |
| 32 | - public function exists($key) { | |
| 40 | + public function exists($key): bool | |
| 41 | + { | |
| 33 | 42 | |
| 34 | 43 | return $this->get( $key ) !== false; |
| 35 | 44 | } |
| 36 | 45 | |