diff --git a/dvg_appointments.client.inc b/dvg_appointments.client.inc
index 9bf3bea..9d94d39 100644
--- a/dvg_appointments.client.inc
+++ b/dvg_appointments.client.inc
@@ -17,17 +17,19 @@ abstract class AppointmentsClientApi {
 
       ksort($args);
       $cid = 'dvg_appointments__' . $function . '__' . substr(md5(serialize($args)), 0, 8);
-      if (!$reset && $cache = cache_get($cid)) {
+      $cache = cache_get($cid);
+      if (!$reset && $cache) {
 
         // Make sure the cache isn't expired.
-        if ($cache->expire > REQUEST_TIME) {
+        $expired = REQUEST_TIME > $cache->expire;
+        if (!$expired) {
           return $cache->data;
         }
       }
       if ($this->api_method == 'soap') {
         $return = $this->soap_client->{$function}($args);
       }
-      elseif ($this->api_method == 'rest'){
+      elseif ($this->api_method == 'rest') {
         $rest_url = $this->url . $args['rest_url'];
         $method = $args['rest_method'];
         $rest_url_parameters = (isset($args['rest_url_parameters'])) ? $args['rest_url_parameters'] : array();
@@ -61,15 +63,21 @@ abstract class AppointmentsClientApi {
       $expires = $this->get_cache_expire();
       $function_expire = isset($expires[$function]) ? $expires[$function] : variable_get('dvg_appointments__cache_default', 3600);
 
+      // The default function expire is FALSE. When this variable is set to
+      // a expire date and the return is not empty then the cache will be reset.
       $custom_function_expire = variable_get('dvg_appointments__cache__' . $function, FALSE);
 
+      // Set expired to false because we don't want to override
+      // cache with empty values.
       if ($function == 'getAvailableProducts' && empty($return)) {
         watchdog('appointment_api', 'Empty return value: @function', array('@function' => $function), WATCHDOG_WARNING);
         $custom_function_expire = FALSE;
+        $expired = FALSE;
       }
 
-      // Store the results in cache.
-      if ($custom_function_expire || $custom_function_expire === FALSE) {
+      // Store the results in cache if the cache hasn't been set.
+      // When custom_function_expire is set reset the cache.
+      if (!$cache || $expired || $custom_function_expire) {
         $expire = REQUEST_TIME + ($custom_function_expire ? $custom_function_expire : $function_expire);
         cache_set($cid, $return, 'cache', $expire);
       }
