Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php |
— | — | @@ -848,7 +848,9 @@ |
849 | 849 | // use cache if allowed |
850 | 850 | if ( $sfgCacheFormDefinitions && $form_id !== null ) { |
851 | 851 | |
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 | + |
853 | 855 | $cached_def = self::getFormCache()->get( $cachekey ); |
854 | 856 | |
855 | 857 | // Cache hit? |
— | — | @@ -890,15 +892,16 @@ |
891 | 893 | // parse wiki-text |
892 | 894 | $output = $tmpParser->parse( $form_def, $title, $tmpParser->getOptions() ); |
893 | 895 | $form_def = $output->getText(); |
| 896 | + $expiry = $output->getCacheExpiry(); |
894 | 897 | |
895 | 898 | // store in cache if allowed |
896 | 899 | if ( $sfgCacheFormDefinitions && $form_id !== null ) { |
897 | 900 | |
898 | | - if ( $output->getCacheTime() == -1 ) { |
| 901 | + if ( $expiry == 0 ) { |
| 902 | + self::purgeCache( $form_article ); |
899 | 903 | wfDebug( "Caching disabled for form definition $cachekey\n" ); |
900 | | - self::purgeCache( $form_article ); |
901 | 904 | } else { |
902 | | - wfGetMainCache()->add( $cachekey, $form_def ); |
| 905 | + self::getFormCache()->set( $cachekey, $form_def, $expiry ); |
903 | 906 | wfDebug( "Cached form definition $cachekey\n" ); |
904 | 907 | } |
905 | 908 | |
— | — | @@ -914,13 +917,27 @@ |
915 | 918 | * @param Page $wikipage |
916 | 919 | * @return Bool |
917 | 920 | */ |
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 ) ) { |
920 | 924 | |
921 | | - $key = wfMemcKey('ext.SemanticForms.formdefinition', $wikipage->getId() ); |
| 925 | + $keyToPurge = self::getCacheKey( ( is_null( $wikipage ) ) ? null : $wikipage->getId() ); |
| 926 | + |
| 927 | + $len = strlen( $keyToPurge ); |
922 | 928 | |
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 | + |
925 | 942 | } |
926 | 943 | } |
927 | 944 | |
— | — | @@ -934,5 +951,33 @@ |
935 | 952 | global $sfgFormCacheType, $wgParserCacheType; |
936 | 953 | $ret = & wfGetCache( ( $sfgFormCacheType !== null ) ? $sfgFormCacheType : $wgParserCacheType ); |
937 | 954 | 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 | + |
938 | 984 | } |
939 | | -} |