@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 96 lines 2.0 kB view raw
1<?php 2 3/** 4 * Interface to the APC key-value cache. This is a very high-performance cache 5 * which is local to the current machine. 6 */ 7final class PhutilAPCKeyValueCache extends PhutilKeyValueCache { 8 9 10/* -( Key-Value Cache Implementation )------------------------------------- */ 11 12 13 public function isAvailable() { 14 return function_exists('apcu_fetch') && 15 ini_get('apc.enabled') && 16 (ini_get('apc.enable_cli') || php_sapi_name() != 'cli'); 17 } 18 19 public function getKeys(array $keys, $ttl = null) { 20 static $is_apcu; 21 if ($is_apcu === null) { 22 $is_apcu = self::isAPCu(); 23 } 24 25 $results = array(); 26 $fetched = false; 27 foreach ($keys as $key) { 28 if (!$is_apcu) { 29 continue; 30 } 31 $result = apcu_fetch($key, $fetched); 32 if ($fetched) { 33 $results[$key] = $result; 34 } 35 } 36 return $results; 37 } 38 39 public function setKeys(array $keys, $ttl = 0) { 40 static $is_apcu; 41 if ($is_apcu === null) { 42 $is_apcu = self::isAPCu(); 43 } 44 45 if ($ttl === null) { 46 $ttl = 0; 47 } 48 49 // NOTE: Although late APC supported passing an array to `apc_store()`, 50 // it was not supported by older versions of APC or by HPHP. 51 52 // See T13525 for discussion of use of "@" to silence this warning: 53 // > GC cache entry "<some-key-name>" was on gc-list for <X> seconds 54 55 foreach ($keys as $key => $value) { 56 if ($is_apcu) { 57 @apcu_store($key, $value, $ttl); 58 } 59 } 60 61 return $this; 62 } 63 64 public function deleteKeys(array $keys) { 65 static $is_apcu; 66 if ($is_apcu === null) { 67 $is_apcu = self::isAPCu(); 68 } 69 70 foreach ($keys as $key) { 71 if ($is_apcu) { 72 apcu_delete($key); 73 } 74 } 75 76 return $this; 77 } 78 79 public function destroyCache() { 80 static $is_apcu; 81 if ($is_apcu === null) { 82 $is_apcu = self::isAPCu(); 83 } 84 85 if ($is_apcu) { 86 apcu_clear_cache(); 87 } 88 89 return $this; 90 } 91 92 private static function isAPCu() { 93 return function_exists('apcu_fetch'); 94 } 95 96}