? 199774-19.automatic_update_emails.patch ? 199774-automatic_update_emails-rev5.patch ? 312393-node-update-index-slow.patch ? 336483-add-index-for-comment-count-rev3.patch ? 336483-add-index-for-comment-count.patch ? 534092-cache-returns-expired-objects-rev2.patch ? 534092-cache-returns-expired-objects-rev3.patch ? 534092-cache-returns-expired-objects-rev4.patch ? changes.patch ? modules/search/search.module-test Index: includes/cache.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/cache.inc,v retrieving revision 1.38 diff -u -p -r1.38 cache.inc --- includes/cache.inc 1 Jul 2009 12:47:30 -0000 1.38 +++ includes/cache.inc 31 Jul 2009 14:39:18 -0000 @@ -42,7 +42,15 @@ function _cache_get_object($bin) { * @return 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 > REQUEST_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.9 diff -u -p -r1.9 cache.test --- modules/simpletest/tests/cache.test 13 Jul 2009 21:51:41 -0000 1.9 +++ modules/simpletest/tests/cache.test 31 Jul 2009 14:39:21 -0000 @@ -152,6 +152,18 @@ 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 that expired 10 seconds ago. + cache_set('expired_test_string', $test_string, 'cache', REQUEST_TIME - 10); + $this->assertCacheExists(t('Expired cache item found in cache'), $test_string, 'expired_test_string', 'cache'); + $this->assertFalse(cache_get('expired_test_string'), t('Expired cache item not returned by cache')); + } + /* * Check or a variable is stored and restored properly. **/ @@ -312,3 +324,5 @@ class CacheClearCase extends CacheTestCa t('All cache entries removed when the array exceeded the cache clear threshold.')); } } + +