From a2c4237098670327aaa22145425692fbb14bc127 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 13 May 2015 20:28:16 -0700 Subject: [PATCH] Added WANObjectCache::TTL_UNCACHEABLE for uncacheable content Change-Id: If7b75654c91cc5762cb49d90f40e1b7ea518ebc8 --- includes/libs/objectcache/WANObjectCache.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 0ca0f2e616..8d202c74ca 100755 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -76,6 +76,8 @@ class WANObjectCache { /** Idiom for set()/getWithSetCallback() TTL */ const TTL_NONE = 0; + /** Idiom for getWithSetCallback() callbacks to avoid calling set() */ + const TTL_UNCACHEABLE = -1; /** Cache format version number */ const VERSION = 1; @@ -365,7 +367,9 @@ class WANObjectCache { * * @param string $key Cache key * @param callable $callback Value generation function - * @param integer $ttl Seconds to live when the key is updated [0=forever] + * @param integer $ttl Seconds to live for key updates. Special values are: + * - WANObjectCache::TTL_NONE : cache forever + * - WANObjectCache::TTL_UNCACHEABLE : do not cache at all * @param array $checkKeys List of "check" keys * @param array $opts Options map: * - lowTTL : consider pre-emptive updates when the current TTL (sec) @@ -432,7 +436,7 @@ class WANObjectCache { $value = call_user_func_array( $callback, array( $cValue, &$ttl ) ); // When delete() is called, writes are write-holed by the tombstone, // so use a special stash key to pass the new value around threads. - if ( $value !== false && ( $isHot || $isTombstone ) ) { + if ( $value !== false && ( $isHot || $isTombstone ) && $ttl >= 0 ) { $this->cache->set( self::STASH_KEY_PREFIX . $key, $value, $tempTTL ); } @@ -440,7 +444,7 @@ class WANObjectCache { $this->cache->unlock( $key ); } - if ( $value !== false ) { + if ( $value !== false && $ttl >= 0 ) { // Update the cache; this will fail if the key is tombstoned $this->set( $key, $value, $ttl ); } -- 2.20.1