@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
at recaptime-dev/main 65 lines 1.5 kB view raw
1<?php 2 3final class PhutilKeyValueCacheNamespace extends PhutilKeyValueCacheProxy { 4 5 private $namespace; 6 7 public function setNamespace($namespace) { 8 if (strpos($namespace, ':') !== false) { 9 throw new Exception(pht("Namespace can't contain colons.")); 10 } 11 12 $this->namespace = $namespace.':'; 13 14 return $this; 15 } 16 17 public function setKeys(array $keys, $ttl = null) { 18 return parent::setKeys(array_combine( 19 $this->prefixKeys(array_keys($keys)), 20 $keys), $ttl); 21 } 22 23 public function getKeys(array $keys) { 24 $results = parent::getKeys($this->prefixKeys($keys)); 25 26 if (!$results) { 27 return array(); 28 } 29 30 return array_combine( 31 $this->unprefixKeys(array_keys($results)), 32 $results); 33 } 34 35 public function deleteKeys(array $keys) { 36 return parent::deleteKeys($this->prefixKeys($keys)); 37 } 38 39 private function prefixKeys(array $keys) { 40 if ($this->namespace == null) { 41 throw new Exception(pht('Namespace not set.')); 42 } 43 44 $prefixed_keys = array(); 45 foreach ($keys as $key) { 46 $prefixed_keys[] = $this->namespace.$key; 47 } 48 49 return $prefixed_keys; 50 } 51 52 private function unprefixKeys(array $keys) { 53 if ($this->namespace == null) { 54 throw new Exception(pht('Namespace not set.')); 55 } 56 57 $unprefixed_keys = array(); 58 foreach ($keys as $key) { 59 $unprefixed_keys[] = substr($key, strlen($this->namespace)); 60 } 61 62 return $unprefixed_keys; 63 } 64 65}