diff --git a/sites/all/modules/contrib/memcache/memcache.inc b/sites/all/modules/contrib/memcache/memcache.inc
index 1344bd2..cecdd0f 100644
--- a/sites/all/modules/contrib/memcache/memcache.inc
+++ b/sites/all/modules/contrib/memcache/memcache.inc
@@ -56,6 +56,18 @@ function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $he
 
   // Save to memcache
   if ($expire == CACHE_TEMPORARY) {
+    // Convert CACHE_TEMPORARY (-1) into something that will live in memcache
+    // until the next flush.
+    $cache->expire = time() + 2591999;
+  }
+  // Expire time is in seconds if less than 30 days, otherwise is a timestamp.
+  else if ($expire != CACHE_PERMANENT && $expire < 2592000) {
+    // Expire is expressed in seconds, convert to the proper future timestamp
+    // as expected in dmemcache_get().
+    $cache->expire = time() + $expire;
+  }
+  else {
+    $cache->expire = $expire;
     $expire = variable_get('cache_lifetime', 2591999);
   }
   // We manually track the expire time in $cache->expire.  When the object
