How do I cache a custom module that has points? I am making a site with users that have points. I have a custom module that calculates points for each user, but the page is slow when is calculating the points in real time, so what I want to do is making a cache the points so they don't need to be calculated anytime someone open the page. The page will be cached; if users want the status for their points, they can update them pressing the "Update" button. So I will write a function for that button to clear the cache.
Yes, you can use the Drupal cache API to set and get the data from cache.

Assuming D7, The following resources have some good information on that:


https://www.lullabot.com/articles/a-beginners-guide-to-caching-data-in-drupal-7
https://www.drupal.org/docs/7/managing-site-performance-and-scalability/caching-to-improve-performance/caching-overview


For example:

function MYMODULE_function() {
  global $user;
  $user_point_data = &amp;drupal_static(__FUNCTION__ . $user-&gt;uid);
  if (!isset($user_point_data)) {
    // User per user cache id for points.
    $cid = 'user_point_data:' . $user-&gt;uid;
    if ($cache = cache_get($cid)) {
      $user_point_data = $cache-&gt;data;
    }
    else {
      // Do your expensive calculations here, and populate $user_point_data
      // with the correct stuff..
      cache_set($cid, $user_point_data, 'cache');
    }
  }
  return $user_point_data;
}


You can then clear the cached data, based on specific user id or all items, with: 

cache_clear_all

// Clear all user point data from cache
cache_clear_all('user_point_data', 'cache', TRUE);
// Clear specific user point data from cache
$cid = 'user_point_data:' . $GLOBALS['user']-&gt;uid;
cache_clear_all($cid, 'cache');