Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php |
— | — | @@ -20,8 +20,7 @@ |
21 | 21 | global $wgParser, $wgMemc; |
22 | 22 | wfProfileIn( __METHOD__ ); |
23 | 23 | $versions = false; |
24 | | - $hash = md5( $article->getTitle()->getPrefixedDBkey() ); |
25 | | - $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $rev->getId(), $hash ); |
| 24 | + $key = self::getCacheKey( $article->getTitle(), $rev->getId() ); |
26 | 25 | if ( $regen !== 'regen' ) { // check cache |
27 | 26 | $versions = FlaggedRevs::getMemcValue( $wgMemc->get( $key ), $article, 'allowStale' ); |
28 | 27 | } |
— | — | @@ -48,13 +47,14 @@ |
49 | 48 | } |
50 | 49 | # Get the template/file versions used... |
51 | 50 | $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() ); |
52 | | - # Save to cache... |
| 51 | + # Save to cache (check cache expiry for dynamic elements)... |
53 | 52 | $data = FlaggedRevs::makeMemcObj( $versions ); |
54 | | - $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic |
| 53 | + $wgMemc->set( $key, $data, $pOut->getCacheExpiry() ); |
55 | 54 | } else { |
| 55 | + $tVersions =& $versions[0]; // templates |
56 | 56 | # Do a link batch query for page_latest... |
57 | 57 | $lb = new LinkBatch(); |
58 | | - foreach ( $versions as $ns => $tmps ) { |
| 58 | + foreach ( $tVersions as $ns => $tmps ) { |
59 | 59 | foreach ( $tmps as $dbKey => $revIdDraft ) { |
60 | 60 | $lb->add( $ns, $dbKey ); |
61 | 61 | } |
— | — | @@ -62,9 +62,9 @@ |
63 | 63 | $lb->execute(); |
64 | 64 | # Update array with the current page_latest values. |
65 | 65 | # This kludge is there since $newTemplates (thus $revIdDraft) is cached. |
66 | | - foreach ( $versions as $ns => $tmps ) { |
| 66 | + foreach ( $tVersions as $ns => &$tmps ) { |
67 | 67 | foreach ( $tmps as $dbKey => &$revIdDraft ) { |
68 | | - $title = new Title( $ns, $dbKey ); |
| 68 | + $title = Title::makeTitle( $ns, $dbKey ); |
69 | 69 | $revIdDraft = (int)$title->getLatestRevID(); |
70 | 70 | } |
71 | 71 | } |
— | — | @@ -82,12 +82,16 @@ |
83 | 83 | */ |
84 | 84 | public static function setRevIncludes( Title $title, $revId, ParserOutput $pOut ) { |
85 | 85 | global $wgMemc; |
86 | | - $hash = md5( $title->getPrefixedDBkey() ); |
87 | | - $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $revId, $hash ); |
| 86 | + $key = self::getCacheKey( $title, $revId ); |
88 | 87 | # Get the template/file versions used... |
89 | 88 | $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() ); |
90 | | - # Save to cache... |
| 89 | + # Save to cache (check cache expiry for dynamic elements)... |
91 | 90 | $data = FlaggedRevs::makeMemcObj( $versions ); |
92 | | - $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic |
| 91 | + $wgMemc->set( $key, $data, $pOut->getCacheExpiry() ); |
93 | 92 | } |
| 93 | + |
| 94 | + protected static function getCacheKey( Title $title, $revId ) { |
| 95 | + $hash = md5( $title->getPrefixedDBkey() ); |
| 96 | + return wfMemcKey( 'flaggedrevs', 'revIncludes', $revId, $hash ); |
| 97 | + } |
94 | 98 | } |