Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
add our own (minimal) term caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Jan 31, 2014
1 parent 811dd87 commit e21f86d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion helpers/cmb_Meta_Box_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,18 @@ public static function is_valid_img_ext( $file ) {
public static function get_object_terms( $object_id, $taxonomy ) {

if ( ! $post = get_post( $object_id ) ) {
return wp_get_object_terms( $object_id, $taxonomy );

$cache_key = 'cmb-cache-'. $taxonomy .'-'. $object_id;

// Check cache
$cached = $test = get_transient( $cache_key );
if ( $cached )
return $cached;

$cached = wp_get_object_terms( $object_id, $taxonomy );
// Do our own (minimal) caching. Long enough for a page-load.
$set = set_transient( $cache_key, $cached, 60 );
return $cached;
}

// WP caches internally so it's better to use
Expand Down

0 comments on commit e21f86d

Please sign in to comment.