| @@ -1,18 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +defined( 'ABSPATH' ) || exit(); | |
| 3 | + | |
| 4 | +if ( class_exists( 'Thim_Cache_DB' ) ) { | |
| 5 | + return; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Class Thim_Cache_DB |
| 4 | 10 | * |
| 5 | 11 | * @author tungnx |
| 6 | - * @version 1.0.0 | |
| 12 | + * @version 1.0.1 | |
| 7 | 13 | * @since 4.2.2 |
| 8 | 14 | */ |
| 9 | -defined( 'ABSPATH' ) || exit(); | |
| 10 | - | |
| 11 | -if ( class_exists( 'Thim_Cache_DB' ) ) { | |
| 12 | - return; | |
| 13 | -} | |
| 14 | - | |
| 15 | 15 | class Thim_Cache_DB { |
| 16 | 16 | private static $_instance = null; |
| 17 | 17 | private $action = null; // one of insert/update |
| 18 | 18 | const ACTION_INSERT = 'insert'; |
| @@ -62,18 +62,28 @@ | ||
| 62 | 62 | * @return bool|string |
| 63 | 63 | */ |
| 64 | 64 | public function get_value( string $key_cache ) { |
| 65 | 65 | $sql = $this->wpdb->prepare( |
| 66 | - "SELECT `value` FROM {$this->table_name} WHERE `key_cache` = %s", | |
| 66 | + "SELECT `value`, `expiration` FROM {$this->table_name} WHERE `key_cache` = %s", | |
| 67 | 67 | $key_cache |
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | - $result = $this->wpdb->get_var( $sql ); | |
| 70 | + $result = $this->wpdb->get_row( $sql ); | |
| 71 | 71 | if ( is_null( $result ) ) { |
| 72 | 72 | return false; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - return $result; | |
| 75 | + $expiration = (int) ( $result->expiration ?? 0 ); | |
| 76 | + if ( $expiration > 0 && $expiration < time() ) { | |
| 77 | + try { | |
| 78 | + $this->remove_cache( $key_cache ); | |
| 79 | + } catch ( Throwable $e ) { | |
| 80 | + LP_Debug::error_log( $e ); | |
| 81 | + } | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + | |
| 85 | + return $result->value; | |
| 76 | 86 | } |
| 77 | 87 | |
| 78 | 88 | /** |
| 79 | 89 | * Get value by key_cache |