r103234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103233‎ | r103234 | r103235 >
Date:21:55, 15 November 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
followup rr102726: Use optionsHash to create cache key
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php
@@ -848,7 +848,9 @@
849849 // use cache if allowed
850850 if ( $sfgCacheFormDefinitions && $form_id !== null ) {
851851
852 - $cachekey = wfMemcKey('ext.SemanticForms.formdefinition', $form_id);
 852+ // create a cache key consisting of owner name, article id and user options
 853+ $cachekey = self::getCacheKey( $form_id, $parser );
 854+
853855 $cached_def = self::getFormCache()->get( $cachekey );
854856
855857 // Cache hit?
@@ -890,15 +892,16 @@
891893 // parse wiki-text
892894 $output = $tmpParser->parse( $form_def, $title, $tmpParser->getOptions() );
893895 $form_def = $output->getText();
 896+ $expiry = $output->getCacheExpiry();
894897
895898 // store in cache if allowed
896899 if ( $sfgCacheFormDefinitions && $form_id !== null ) {
897900
898 - if ( $output->getCacheTime() == -1 ) {
 901+ if ( $expiry == 0 ) {
 902+ self::purgeCache( $form_article );
899903 wfDebug( "Caching disabled for form definition $cachekey\n" );
900 - self::purgeCache( $form_article );
901904 } else {
902 - wfGetMainCache()->add( $cachekey, $form_def );
 905+ self::getFormCache()->set( $cachekey, $form_def, $expiry );
903906 wfDebug( "Cached form definition $cachekey\n" );
904907 }
905908
@@ -914,13 +917,27 @@
915918 * @param Page $wikipage
916919 * @return Bool
917920 */
918 - public static function purgeCache ( &$wikipage ) {
919 - if ( $wikipage->getTitle()->getNamespace() == SF_NS_FORM ) {
 921+ public static function purgeCache ( &$wikipage = null ) {
 922+
 923+ if ( is_null( $wikipage ) || ( $wikipage->getTitle()->getNamespace() == SF_NS_FORM ) ) {
920924
921 - $key = wfMemcKey('ext.SemanticForms.formdefinition', $wikipage->getId() );
 925+ $keyToPurge = self::getCacheKey( ( is_null( $wikipage ) ) ? null : $wikipage->getId() );
 926+
 927+ $len = strlen( $keyToPurge );
922928
923 - if ( self::getFormCache()->delete($key) ) {
924 - wfDebug( "Deleted cached form definition $key.\n" );
 929+ $cache = self::getFormCache();
 930+ $keysInCache = $cache->keys();
 931+
 932+ foreach ( $keysInCache as $curKey ) {
 933+
 934+ if ( strncmp( $curKey, $keyToPurge, $len ) === 0 ) {
 935+
 936+ if ( self::getFormCache()->delete( $curKey ) ) {
 937+ wfDebug( "Deleted cached form definition $curKey.\n" );
 938+ }
 939+
 940+ }
 941+
925942 }
926943 }
927944
@@ -934,5 +951,33 @@
935952 global $sfgFormCacheType, $wgParserCacheType;
936953 $ret = & wfGetCache( ( $sfgFormCacheType !== null ) ? $sfgFormCacheType : $wgParserCacheType );
937954 return $ret;
 955+ }
 956+
 957+
 958+ /**
 959+ * Get a cache key.
 960+ *
 961+ * @param $formId or null
 962+ * @param Parser $parser or null
 963+ * @return String
 964+ */
 965+ public static function getCacheKey( $formId = null, &$parser = null ) {
 966+
 967+ if ( is_null( $formId ) ) {
 968+ return wfMemcKey( 'ext.SemanticForms.formdefinition' );
 969+ } else if ( is_null( $parser ) ) {
 970+ return wfMemcKey( 'ext.SemanticForms.formdefinition', $formId );
 971+ } else {
 972+ if ( method_exists( 'ParserOptions', 'optionsHash' ) ) {
 973+ $optionsHash = $parser->getOptions()->optionsHash( ParserOptions::legacyOptions() );
 974+ } else {
 975+ $optionsHash = $parser->getOptions()->getUser()->getPageRenderingHash();
 976+ }
 977+
 978+ return wfMemcKey(
 979+ 'ext.SemanticForms.formdefinition', $formId, $optionsHash
 980+ );
 981+ }
 982+ }
 983+
938984 }
939 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r103241followup r103234: bug fix (incompatible with MW 1.16)foxtrott22:09, 15 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102726Enable caching for formdefinitionsfoxtrott00:20, 11 November 2011