Skip to content
Browse files

add our own (minimal) term caching

  • Loading branch information...
1 parent 811dd87 commit e21f86d6852fb04db3ba2f0dced4b1e35e845227 @jtsternberg jtsternberg committed Jan 31, 2014
Showing with 12 additions and 1 deletion.
  1. +12 −1 helpers/cmb_Meta_Box_types.php
View
13 helpers/cmb_Meta_Box_types.php
@@ -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

0 comments on commit e21f86d

Please sign in to comment.
Something went wrong with that request. Please try again.