Index: trunk/phase3/includes/filerepo/FileCache.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | */ |
11 | 11 | class FileCache { |
12 | 12 | var $repoGroup; |
13 | | - var $cache = array(), $notFound = array(); |
| 13 | + var $cache = array(), $oldCache = array(), $notFound = array(); |
14 | 14 | |
15 | 15 | protected static $instance; |
16 | 16 | |
— | — | @@ -87,10 +87,10 @@ |
88 | 88 | /** |
89 | 89 | * Search the cache for a file. |
90 | 90 | * @param mixed $title Title object or string |
| 91 | + * @param string or false $time, old version time |
91 | 92 | * @return File object or false if it is not found |
92 | | - * @todo Implement searching for old file versions(?) |
93 | 93 | */ |
94 | | - function findFile( $title ) { |
| 94 | + function findFile( $title, $time = false ) { |
95 | 95 | if( !( $title instanceof Title ) ) { |
96 | 96 | $title = Title::makeTitleSafe( NS_FILE, $title ); |
97 | 97 | } |
— | — | @@ -99,20 +99,37 @@ |
100 | 100 | } |
101 | 101 | |
102 | 102 | $dbkey = $title->getDBkey(); |
| 103 | + # Is there a current version cached? |
103 | 104 | if( array_key_exists( $dbkey, $this->cache ) ) { |
104 | | - wfDebug( "FileCache HIT for $dbkey\n" ); |
105 | | - return $this->cache[$dbkey]; |
| 105 | + if( !$time || $this->cache[$dbkey]->getTimestamp() === $time ) { |
| 106 | + wfDebug( "FileCache HIT for $dbkey\n" ); |
| 107 | + return $this->cache[$dbkey]; |
| 108 | + } |
106 | 109 | } |
| 110 | + # Is there no current version? Then assume no old versions too. |
107 | 111 | if( array_key_exists( $dbkey, $this->notFound ) ) { |
108 | 112 | wfDebug( "FileCache negative HIT for $dbkey\n" ); |
109 | 113 | return false; |
110 | 114 | } |
| 115 | + # Is this old version cached? |
| 116 | + if( $time && array_key_exists( $dbkey, $this->oldCache ) && |
| 117 | + array_key_exists( $time, $this->oldCache[$dbkey] ) ) |
| 118 | + { |
| 119 | + wfDebug( "FileCache HIT for $dbkey on $time\n" ); |
| 120 | + return $this->oldCache[$dbkey][$time]; |
| 121 | + } |
111 | 122 | |
112 | 123 | // Not in cache, fall back to a direct query |
113 | | - $file = $this->repoGroup->findFile( $title ); |
| 124 | + $file = $this->repoGroup->findFile( $title, $time ); |
114 | 125 | if( $file ) { |
115 | 126 | wfDebug( "FileCache MISS for $dbkey\n" ); |
116 | | - $this->cache[$dbkey] = $file; |
| 127 | + if( !$file->isOld() ) { |
| 128 | + $this->cache[$dbkey] = $file; // cache the current version |
| 129 | + } |
| 130 | + if( !array_key_exists( $dbkey, $this->oldCache ) ) { |
| 131 | + $this->oldCache[$dbkey] = array(); |
| 132 | + } |
| 133 | + $this->oldCache[$dbkey][$file->getTimestamp()] = $file; // cache this version |
117 | 134 | } else { |
118 | 135 | wfDebug( "FileCache negative MISS for $dbkey\n" ); |
119 | 136 | $this->notFound[$dbkey] = true; |