Skip to content

Commit 1ac2905

Browse files
committed
Fixed Cache bug
1 parent faf2e4c commit 1ac2905

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Release changes are noted on the [Releases](https://github.com/dmhendricks/wordp
5959

6060
* Bumped minimum PHP version check to 5.4
6161
* Added initial `plugin.json` for configuration
62+
* Fixed caching expiration bug
6263

6364
## Credits
6465

app/Cache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class Cache extends Plugin {
1313
*/
1414
public static function get_object( $key = null, $callback ) {
1515

16-
$object_cache_group = isset( self::$settings['object_cache_group']) && self::$settings['object_cache_group'] ?: sanitize_title( self::$settings['data']['Name'] );
16+
$object_cache_group = isset( self::$settings['object_cache']['group'] ) && self::$settings['object_cache']['group'] ? self::$settings['object_cache']['group'] : sanitize_title( self::$settings['data']['Name'] );
1717
if( is_multisite() ) $object_cache_group .= '_' . get_current_blog_id();
18-
$object_cache_expire = self::$settings['object_cache_expire'] ?: 86400; // Default to 24 hours of null
18+
$object_cache_expire = ( isset( self::$settings['object_cache']['expire_hours'] ) && is_int( self::$settings['object_cache']['expire_hours'] ) ? self::$settings['object_cache']['expire_hours'] : 24 ) * 86400; // Default to 24 hours
1919

2020
// Set key variable
2121
$object_cache_key = $key . ( is_multisite() ? '_' . get_current_blog_id() : '' );
@@ -25,7 +25,7 @@ public static function get_object( $key = null, $callback ) {
2525
if( $result && is_serialized( $result ) ) $result = unserialize($result);
2626

2727
// If result wasn't found/returned and/or caching is disabled, set & return the value from $callback
28-
if(true || !$result) {
28+
if( !$result ) {
2929
$result = $callback();
3030
if( is_array( $result ) || is_object( $result ) ) $set_result = serialize( $result );
3131
wp_cache_set( $object_cache_key, $set_result, $object_cache_group, $object_cache_expire);

0 commit comments

Comments
 (0)