@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3abstract class DivinerDiskCache extends Phobject {
4
5 private $cache;
6
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;
14 }
15
16 protected function getCache() {
17 return $this->cache;
18 }
19
20 public function delete() {
21 $this->getCache()->destroyCache();
22 return $this;
23 }
24
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.
31 */
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 ));
40 }
41
42}