wiki.techinc.nl/includes/cache/ObjectFileCache.php
Aaron Schulz 6014f0db91 HTMLFileCache refactoring:
* Rewrote class and split into three classes: a base class, and html cache and a more generic cache to be used later.
* The new classes now use RequestContext.
* Renamed fetchPageText() -> fetchText().
* Split out new saveText() function from saveToFileCache().
* Various other cleanups and fixes.
Also fixed backwards setting of $wgDisableCounters in rebuildFileCache.php.
2011-09-29 08:18:20 +00:00

41 lines
1 KiB
PHP

<?php
class ObjectFileCache extends FileCacheBase {
public static function newFromKey( $key, $type ) {
$cache = new self();
$allowedTypes = self::cacheableTypes();
if ( !isset( $allowedTypes[$type] ) ) {
throw new MWException( "Invalid filecache type given." );
}
$cache->mKey = (string)$key;
$cache->mType = (string)$type;
$cache->mExt = $allowedTypes[$cache->mType];
return $cache;
}
/*
* Get the type => extension mapping
* @return array
*/
protected static function cacheableTypes() {
return array( 'resources-js' => 'js', 'resources-css' => 'css' );
}
/**
* Get the base file cache directory
* @return string
*/
protected function cacheDirectory() {
global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
if ( $wgFileCacheDirectory ) {
$dir = $wgFileCacheDirectory;
} elseif ( $wgCacheDirectory ) {
$dir = "$wgCacheDirectory/object";
} else {
throw new MWException( 'Please set $wgCacheDirectory in LocalSettings.php if you wish to use the HTML file cache' );
}
return $dir;
}
}