1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-27 14:09:11 +01:00
phorge-phorge/src/applications/diviner/cache/DivinerDiskCache.php
Joshua Spence 6b7d7401ca Modernize Diviner
Summary:
Ref T4558. This diff modernizes the #diviner application. Basically:

  - Add an edit controller, accessible at `/book/$BOOK/edit/`.
  - Add edit/view policies.
  - Added an action menu to the `DivinerBookController` to expose the edit interface.
  - Allows projects to be associated with books.
  - Implement edges and transactions.
  - Implemented `PhabricatorApplicationTransactionInterface` in `DivinerLiveBook`.

Test Plan:
  - Generated a Diviner book with `./bin/diviner generate`.
  - Added projects to a book and ensured that they persisted.
  - Changed the view policy on a book and made sure it was effective.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4558

Differential Revision: https://secure.phabricator.com/D13091
2015-06-17 07:17:14 +10:00

42 lines
1.1 KiB
PHP

<?php
abstract class DivinerDiskCache extends Phobject {
private $cache;
public function __construct($cache_directory, $name) {
$dir_cache = id(new PhutilDirectoryKeyValueCache())
->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
* @{class:PhutilDirectoryKeyValueCache}, this gives us nice directories
* inside `.divinercache` instead of a million hash files with huge names at
* the top level.
*/
protected function getHashKey($hash) {
return implode(
'/',
array(
substr($hash, 0, 2),
substr($hash, 2, 2),
substr($hash, 4, 8),
));
}
}