Created
January 31, 2024 03:58
-
-
Save mehrshaddarzi/69fb3ab32dc6af8a90dcf561eefd897f to your computer and use it in GitHub Desktop.
Option Cache WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check From Cache Option | |
if ($cache) { | |
$option = get_option('wp_hami_products'); | |
if (!empty($option) and is_array($option) and isset($option['list']) and isset($option['expire']) and is_numeric($option['expire']) and $option['expire'] >= current_time('timestamp')) { | |
return [ | |
'status' => true, | |
'list' => $option['list'], | |
'code' => $option['code'], | |
'from' => 'cache' | |
]; | |
} | |
} | |
// Saved Cache | |
if ($cache) { | |
update_option('wp_hami_products', [ | |
'expire' => current_time('timestamp') + (5 * MINUTE_IN_SECONDS), | |
'list' => $data, | |
'code' => $response['code'] | |
], 'no'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment