--- memcache.orig.inc	2009-09-01 11:14:12.000000000 +0100
+++ memcache.inc	2010-02-25 15:06:09.000000000 +0000
@@ -26,11 +26,11 @@ function cache_get($cid, $table = 'cache
     $cache_tables = isset($_SESSION['cache_flush']) ? $_SESSION['cache_flush'] : NULL;
     // Items cached before the cache was last flushed are no longer valid.
     $cache_lifetime = variable_get('cache_lifetime', 0);
-    if ($cache_lifetime && $cache->created && $cache_flush &&
-        ($cache->created < $cache_flush) &&
-        ((time() - $cache->created >= $cache_lifetime)) ||
-        (is_array($cache_tables) && $cache_tables[$table] &&
-        $cache_tables[$table] > $cache->created)) {
+    
+    if (($cache->expire != CACHE_PERMANENT && $cache->expire && $cache->expire < time()) ||
+        ($cache_flush && $cache_flush > $cache->created) ||
+        (is_array($cache_tables) && $cache_tables[$table] && $cache_tables[$table] > $cache->created)) {
+        
       // Cache item expired, return NULL.
       return 0;
     }
@@ -74,7 +74,9 @@ function cache_set($cid, $data, $table =
   if ($expire == CACHE_TEMPORARY) {
     // Convert CACHE_TEMPORARY (-1) into something that will live in memcache
     // until the next flush.
-    $cache->expire = time() + 2591999;
+    
+    $cache_lifetime = variable_get('cache_lifetime', 2591999);
+    $cache->expire = time() + $cache_lifetime;
   }
   // Expire time is in seconds if less than 30 days, otherwise is a timestamp.
   else if ($expire != CACHE_PERMANENT && $expire < 2592000) {
