ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.arConnectorCache.php
Go to the documentation of this file.
1 <?php
2 
22 
27 class arConnectorCache extends arConnector implements Request
28 {
30 
35  public function __construct(private arConnector $arConnector)
36  {
37  global $DIC;
38  $this->cache_container = $DIC->globalCache()->get($this);
39  }
40 
41  protected function buildCacheKey(ActiveRecord $activeRecord): string
42  {
43  return $activeRecord->getConnectorContainerName() . "_" . $activeRecord->getPrimaryFieldValue();
44  }
45 
46  public function getContainerKey(): string
47  {
48  return 'ar_cache';
49  }
50 
51  public function isForced(): bool
52  {
53  return false;
54  }
55 
59  public function nextID(ActiveRecord $activeRecord)
60  {
61  return $this->arConnector->nextID($activeRecord);
62  }
63 
64  public function checkConnection(ActiveRecord $activeRecord): bool
65  {
66  return $this->arConnector->checkConnection($activeRecord);
67  }
68 
69  public function installDatabase(ActiveRecord $activeRecord, array $fields): bool
70  {
71  return $this->arConnector->installDatabase($activeRecord, $fields);
72  }
73 
74  public function updateDatabase(ActiveRecord $activeRecord): bool
75  {
76  return $this->arConnector->updateDatabase($activeRecord);
77  }
78 
79  public function resetDatabase(ActiveRecord $activeRecord): bool
80  {
81  return $this->arConnector->resetDatabase($activeRecord);
82  }
83 
84  public function truncateDatabase(ActiveRecord $activeRecord): bool
85  {
86  return $this->arConnector->truncateDatabase($activeRecord);
87  }
88 
89  public function checkTableExists(ActiveRecord $activeRecord): bool
90  {
91  return $this->arConnector->checkTableExists($activeRecord);
92  }
93 
94  public function checkFieldExists(ActiveRecord $activeRecord, string $field_name): bool
95  {
96  return $this->arConnector->checkFieldExists($activeRecord, $field_name);
97  }
98 
99  public function removeField(ActiveRecord $activeRecord, string $field_name): bool
100  {
101  return $this->arConnector->removeField($activeRecord, $field_name);
102  }
103 
104  public function renameField(ActiveRecord $activeRecord, string $old_name, string $new_name): bool
105  {
106  return $this->arConnector->renameField($activeRecord, $old_name, $new_name);
107  }
108 
109  public function create(ActiveRecord $activeRecord): void
110  {
111  $this->arConnector->create($activeRecord);
112  $this->storeActiveRecordInCache($activeRecord);
113  }
114 
118  public function read(ActiveRecord $activeRecord): array
119  {
120  $key = $this->buildCacheKey($activeRecord);
121  if ($this->cache_container->has($key)) {
122  $cached_value = $this->cache_container->get(
123  $key,
124  new Transformation(fn($value): ?array => is_array($value) ? $value : null)
125  );
126  if (is_array($cached_value)) {
127  return array_map(fn($result): \stdClass => (object) $result, $cached_value);
128  }
129  }
130 
131  $results = $this->arConnector->read($activeRecord);
132 
133  $this->cache_container->set(
134  $key,
135  array_map(fn($result): array => (array) $result, $results)
136  );
137 
138  return $results;
139  }
140 
141  public function update(ActiveRecord $activeRecord): void
142  {
143  $this->arConnector->update($activeRecord);
144  $this->storeActiveRecordInCache($activeRecord);
145  }
146 
147  public function delete(ActiveRecord $activeRecord): void
148  {
149  $this->arConnector->delete($activeRecord);
150  $key = $this->buildCacheKey($activeRecord);
151  $this->cache_container->delete($key);
152  }
153 
157  public function readSet(ActiveRecordList $activeRecordList): array
158  {
159  return $this->arConnector->readSet($activeRecordList);
160  }
161 
162  public function affectedRows(ActiveRecordList $activeRecordList): int
163  {
164  return $this->arConnector->affectedRows($activeRecordList);
165  }
166 
170  public function quote($value, string $type): string
171  {
172  return $this->arConnector->quote($value, $type);
173  }
174 
175  public function updateIndices(ActiveRecord $activeRecord): void
176  {
177  $this->arConnector->updateIndices($activeRecord);
178  }
179 
183  private function storeActiveRecordInCache(ActiveRecord $activeRecord): void
184  {
185  $key = $this->buildCacheKey($activeRecord);
186  $value = $activeRecord->asArray();
187 
188  $this->cache_container->set($key, $value);
189  }
190 }
installDatabase(ActiveRecord $activeRecord, array $fields)
removeField(ActiveRecord $activeRecord, string $field_name)
quote(mixed $value, string $type)
Transform values according to custom configuration.
resetDatabase(ActiveRecord $activeRecord)
installDatabase(ActiveRecord $activeRecord, array $fields)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)
read(ActiveRecord $activeRecord)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkTableExists(ActiveRecord $activeRecord)
resetDatabase(ActiveRecord $activeRecord)
update(ActiveRecord $activeRecord)
updateDatabase(ActiveRecord $activeRecord)
checkConnection(ActiveRecord $activeRecord)
nextID(ActiveRecord $activeRecord)
create(ActiveRecord $activeRecord)
readSet(ActiveRecordList $activeRecordList)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
truncateDatabase(ActiveRecord $activeRecord)
delete(ActiveRecord $activeRecord)
update(ActiveRecord $activeRecord)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
nextID(ActiveRecord $activeRecord)
buildCacheKey(ActiveRecord $activeRecord)
read(ActiveRecord $activeRecord)
removeField(ActiveRecord $activeRecord, string $field_name)
affectedRows(ActiveRecordList $activeRecordList)
updateDatabase(ActiveRecord $activeRecord)
getConnectorContainerName()
Return the Name of your Connector Table
create(ActiveRecord $activeRecord)
global $DIC
Definition: shib_login.php:22
storeActiveRecordInCache(ActiveRecord $activeRecord)
Stores an active record into the Cache.
__construct(private arConnector $arConnector)
ilGSStorageCache constructor.
Class ilGSStorageCache.
$results
checkConnection(ActiveRecord $activeRecord)
updateIndices(ActiveRecord $activeRecord)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
quote($value, string $type)
readSet(ActiveRecordList $activeRecordList)
checkTableExists(ActiveRecord $activeRecord)
affectedRows(ActiveRecordList $activeRecordList)
updateIndices(ActiveRecord $activeRecord)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
truncateDatabase(ActiveRecord $activeRecord)
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)