3 final class PhabricatorUserCache
extends PhabricatorUserDAO
{
11 protected function getConfiguration() {
13 self
::CONFIG_TIMESTAMPS
=> false,
14 self
::CONFIG_COLUMN_SCHEMA
=> array(
15 'cacheIndex' => 'bytes12',
16 'cacheKey' => 'text255',
17 'cacheData' => 'text',
18 'cacheType' => 'text32',
20 self
::CONFIG_KEY_SCHEMA
=> array(
21 'key_usercache' => array(
22 'columns' => array('userPHID', 'cacheIndex'),
25 'key_cachekey' => array(
26 'columns' => array('cacheIndex'),
28 'key_cachetype' => array(
29 'columns' => array('cacheType'),
32 ) + parent
::getConfiguration();
35 public function save() {
36 $this->cacheIndex
= Filesystem
::digestForIndex($this->getCacheKey());
37 return parent
::save();
40 public static function writeCache(
41 PhabricatorUserCacheType
$type,
50 'userPHID' => $user_phid,
51 'value' => $raw_value,
56 public static function writeCaches(array $values) {
57 if (PhabricatorEnv
::isReadOnly()) {
66 $conn_w = $table->establishConnection('w');
69 foreach ($values as $value) {
74 '(%s, %s, %s, %s, %s)',
76 PhabricatorHash
::digestForIndex($key),
79 $value['type']->getUserCacheType());
82 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
84 foreach (PhabricatorLiskDAO
::chunkSQL($sql) as $chunk) {
87 'INSERT INTO %T (userPHID, cacheIndex, cacheKey, cacheData, cacheType)
89 ON DUPLICATE KEY UPDATE
90 cacheData = VALUES(cacheData),
91 cacheType = VALUES(cacheType)',
92 $table->getTableName(),
99 public static function readCaches(
100 PhabricatorUserCacheType
$type,
105 $conn = $table->establishConnection('r');
109 'SELECT userPHID, cacheData FROM %T WHERE userPHID IN (%Ls)
110 AND cacheType = %s AND cacheIndex = %s',
111 $table->getTableName(),
113 $type->getUserCacheType(),
114 PhabricatorHash
::digestForIndex($key));
116 return ipull($rows, 'cacheData', 'userPHID');
119 public static function clearCache($key, $user_phid) {
120 return self
::clearCaches($key, array($user_phid));
123 public static function clearCaches($key, array $user_phids) {
124 if (PhabricatorEnv
::isReadOnly()) {
133 $conn_w = $table->establishConnection('w');
135 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
139 'DELETE FROM %T WHERE cacheIndex = %s AND userPHID IN (%Ls)',
140 $table->getTableName(),
141 PhabricatorHash
::digestForIndex($key),
147 public static function clearCacheForAllUsers($key) {
148 if (PhabricatorEnv
::isReadOnly()) {
153 $conn_w = $table->establishConnection('w');
155 $unguarded = AphrontWriteGuard
::beginScopedUnguardedWrites();
159 'DELETE FROM %T WHERE cacheIndex = %s',
160 $table->getTableName(),
161 PhabricatorHash
::digestForIndex($key));