Skip to content

Instantly share code, notes, and snippets.

@mehrshaddarzi
Created January 31, 2024 03:58
Show Gist options
  • Save mehrshaddarzi/69fb3ab32dc6af8a90dcf561eefd897f to your computer and use it in GitHub Desktop.
Save mehrshaddarzi/69fb3ab32dc6af8a90dcf561eefd897f to your computer and use it in GitHub Desktop.
Option Cache WordPress
// 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