Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / diviner / cache / DivinerDiskCache.php
blobf605796c0c273f3733041b17901d2df84b50b3ef
1 <?php
3 abstract class DivinerDiskCache extends Phobject {
5 private $cache;
7 public function __construct($cache_directory, $name) {
8 $dir_cache = id(new PhutilDirectoryKeyValueCache())
9 ->setCacheDirectory($cache_directory);
10 $profiled_cache = id(new PhutilKeyValueCacheProfiler($dir_cache))
11 ->setProfiler(PhutilServiceProfiler::getInstance())
12 ->setName($name);
13 $this->cache = $profiled_cache;
16 protected function getCache() {
17 return $this->cache;
20 public function delete() {
21 $this->getCache()->destroyCache();
22 return $this;
25 /**
26 * Convert a long-form hash key like `ccbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaN` into
27 * a shortened directory form, like `cc/bb/aaaaaaaaN`. In conjunction with
28 * @{class:PhutilDirectoryKeyValueCache}, this gives us nice directories
29 * inside `.divinercache` instead of a million hash files with huge names at
30 * the top level.
32 protected function getHashKey($hash) {
33 return implode(
34 '/',
35 array(
36 substr($hash, 0, 2),
37 substr($hash, 2, 2),
38 substr($hash, 4, 8),
39 ));