Index: includes/cache.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/cache.inc,v retrieving revision 1.48 diff -u -p -r1.48 cache.inc --- includes/cache.inc 18 May 2010 18:26:30 -0000 1.48 +++ includes/cache.inc 28 Jun 2010 14:44:07 -0000 @@ -47,7 +47,15 @@ function _cache_get_object($bin) { * The cache or FALSE on failure. */ function cache_get($cid, $bin = 'cache') { - return _cache_get_object($bin)->get($cid); + // Check if the object exists in cache. + if ($cached = _cache_get_object($bin)->get($cid)) { + // Check if it is permanently cached (no expiry), or has not expired yet. + if ($cached->expire == CACHE_PERMANENT || $cached->expire > time()) { + return $cached; + } + } + // Either no cache object hit, or the returned object was expired. + return FALSE; } /** Index: modules/simpletest/tests/cache.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/cache.test,v retrieving revision 1.10 diff -u -p -r1.10 cache.test --- modules/simpletest/tests/cache.test 13 Sep 2009 17:49:51 -0000 1.10 +++ modules/simpletest/tests/cache.test 28 Jun 2010 14:44:08 -0000 @@ -152,6 +152,21 @@ class CacheSavingCase extends CacheTestC $this->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.')); } + /** + * Test that expired items are handled properly. + */ + function testExpired() { + $test_string = 'Drupal rocks!'; + + // Set an item in the cache to expire in 10 seconds + cache_set('expired_test_string', $test_string, 'cache', time() + 10); + $this->assertCacheExists(t('Expired cache item found in cache'), $test_string, 'expired_test_string', 'cache'); + sleep(20); + // Cache item should now be expired + $this->assertFalse(cache_get('expired_test_string'), t('Expired cache item not returned by cache')); + } + + /* * Check or a variable is stored and restored properly. **/