From d6445e55a86a7ac96720c94830c9f06d39a85c09 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 5 Sep 2006 14:44:50 +0000 Subject: [PATCH] added getRelatedCache() --- includes/Title.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/includes/Title.php b/includes/Title.php index 7eae801723..cf79780f2c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2244,6 +2244,46 @@ class Title { } } + /** + * Get the last touched timestamp + */ + function getTouched() { + $dbr =& wfGetDB( DB_SLAVE ); + $touched = $dbr->selectField( 'page', 'page_touched', + array( + 'page_namespace' => $this->getNamespace(), + 'page_title' => $this->getDBkey() + ), __METHOD__ + ); + return $touched; + } + + /** + * Get a cached value from a global cache that is invalidated when this page changes + * @param string $key the key + * @param callback $callback A callback function which generates the value on cache miss + */ + function getRelatedCache( $memc, $key, $expiry, $callback, $params = array() ) { + $touched = $this->getTouched(); + $cacheEntry = $memc->get( $key ); + if ( $cacheEntry ) { + if ( $cacheEntry['touched'] >= $touched ) { + return $cacheEntry['value']; + } else { + wfDebug( __METHOD__.": $key expired\n" ); + } + } else { + wfDebug( __METHOD__.": $key not found\n" ); + } + $value = call_user_func_array( $callback, $params ); + $cacheEntry = array( + 'value' => $value, + 'touched' => $touched + ); + $memc->set( $key, $cacheEntry, $expiry ); + return $value; + } + function trackbackURL() { global $wgTitle, $wgScriptPath, $wgServer; -- 2.20.1