Skip to content

Commit 69f4112

Browse files
committed
Improvements
1 parent 1b65a58 commit 69f4112

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

tiny-cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function the_content_cached( $more_link_text = null, $strip_teaser = false ) {
4545
return;
4646
}
4747

48-
$found = null;
48+
$found = false;
4949
$cached = wp_cache_get( $post_id, 'the_content', false, $found );
5050

5151
// Cache hit.
@@ -169,7 +169,7 @@ function get_template_part_cached( $slug, $name = null, $version_hash = '' ) {
169169
}
170170
$key = sprintf( '%s%s:%s', $slug, $file_suffix, $version_hash );
171171

172-
$found = null;
172+
$found = false;
173173
$cached = wp_cache_get( $key, 'template_part', false, $found );
174174

175175
// Cache hit.

tiny-nav-menu-cache.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Tiny navigation menu cache (MU)
44
* Description: Cache nav menu's HTML content in persistent object cache.
5-
* Version: 0.2.0
5+
* Version: 0.2.1
66
* Constants: TINY_CACHE_NAV_MENU_EXCLUDES
77
*/
88

@@ -67,8 +67,7 @@ public function init() {
6767
*/
6868
public function get_nav_menu( $nav_menu_html, $args ) {
6969

70-
$enabled = $this->is_enabled( $args );
71-
if ( $enabled ) {
70+
if ( $this->is_enabled( $args ) ) {
7271
$found = null;
7372
$cache = wp_cache_get( $this->get_cache_key( $args ), self::GROUP, false, $found );
7473
if ( $found ) {
@@ -87,8 +86,7 @@ public function get_nav_menu( $nav_menu_html, $args ) {
8786
*/
8887
public function save_nav_menu( $nav_menu_html, $args ) {
8988

90-
$enabled = $this->is_enabled( $args );
91-
if ( $enabled ) {
89+
if ( $this->is_enabled( $args ) ) {
9290
$key = $this->get_cache_key( $args );
9391
wp_cache_set( $key, $nav_menu_html, self::GROUP, DAY_IN_SECONDS );
9492
$this->remember_key( $key );
@@ -111,13 +109,10 @@ public function flush_all() {
111109
private function remember_key( $key ) {
112110

113111
// @TODO Not atomic
114-
$found = null;
112+
$found = false;
115113
$key_list = wp_cache_get( 'key_list', self::GROUP, false, $found );
116-
if ( $found ) {
117-
$key_list .= '|' . $key;
118-
} else {
119-
$key_list = $key;
120-
}
114+
115+
$key_list = $found ? $key_list . '|' . $key : $key;
121116
wp_cache_set( 'key_list', $key_list, self::GROUP, DAY_IN_SECONDS );
122117
}
123118

0 commit comments

Comments
 (0)