2013-02-17 15:40:00 -08:00
|
|
|
<?php
|
|
|
|
|
2015-06-15 18:02:26 +10:00
|
|
|
abstract class DivinerDiskCache extends Phobject {
|
2013-02-17 15:40:00 -08:00
|
|
|
|
|
|
|
private $cache;
|
|
|
|
|
|
|
|
public function __construct($cache_directory, $name) {
|
2014-08-06 08:12:28 +10:00
|
|
|
$dir_cache = id(new PhutilDirectoryKeyValueCache())
|
2013-02-17 15:40:00 -08:00
|
|
|
->setCacheDirectory($cache_directory);
|
|
|
|
$profiled_cache = id(new PhutilKeyValueCacheProfiler($dir_cache))
|
|
|
|
->setProfiler(PhutilServiceProfiler::getInstance())
|
|
|
|
->setName($name);
|
|
|
|
$this->cache = $profiled_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCache() {
|
|
|
|
return $this->cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete() {
|
|
|
|
$this->getCache()->destroyCache();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a long-form hash key like `ccbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaN` into
|
|
|
|
* a shortened directory form, like `cc/bb/aaaaaaaaN`. In conjunction with
|
2014-08-06 08:12:28 +10:00
|
|
|
* @{class:PhutilDirectoryKeyValueCache}, this gives us nice directories
|
2015-06-17 07:09:53 +10:00
|
|
|
* inside `.divinercache` instead of a million hash files with huge names at
|
|
|
|
* the top level.
|
2013-02-17 15:40:00 -08:00
|
|
|
*/
|
|
|
|
protected function getHashKey($hash) {
|
|
|
|
return implode(
|
|
|
|
'/',
|
|
|
|
array(
|
|
|
|
substr($hash, 0, 2),
|
|
|
|
substr($hash, 2, 2),
|
|
|
|
substr($hash, 4, 8),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|