diff --git a/taxonomy_menu.database.inc b/taxonomy_menu.database.inc
index 2f127e3..3731e9b 100644
--- a/taxonomy_menu.database.inc
+++ b/taxonomy_menu.database.inc
@@ -1,6 +1,4 @@
 <?php
-
-
 /**
  * @file
  * Database functions
@@ -147,16 +145,36 @@ function _taxonomy_menu_get_terms($vid) {
  *
  * used to get the count without children
  *
- * @param $tid
+ * @param int $tid
+ *   Taxonomy term ID.
+ *
+ * @return int
+ *  Count of nodes that reference the term.
  */
 function _taxonomy_menu_term_count($tid) {
+  // Construct a cache ID
+  $cid = 'taxonomy_menu:term_count:' . $tid;
+
+  // Try to get the count from the cache.
+  $cache = cache_get($cid);
+  if ($cache) {
+    return $cache->data;
+  }
+
+  // It is not in the cache, so issue a query.
   $result = db_select('taxonomy_index', 'tn');
   $result->condition('tid', $tid);
   $result->join('node', 'n', 'n.nid = tn.nid AND n.status = 1');
   $result->addExpression('COUNT(n.nid)', 'term_count');
   $temp = $result->execute();
   $temp = $temp->fetchObject();
-  return $temp->term_count;
+  $data = $temp->term_count;
+
+  // Store the count in the cache.
+  cache_set($cid, $data, 'cache', REQUEST_TIME + 1215);
+
+  // Return the result.
+  return $data;
 }
 
 /**
