ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.arConnectorCache.php
Go to the documentation of this file.
1<?php
2
22
27class 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}
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...
getConnectorContainerName()
@description Return the Name of your Connector Table
Transform values according to custom configuration.
Class ilGSStorageCache.
create(ActiveRecord $activeRecord)
readSet(ActiveRecordList $activeRecordList)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
checkTableExists(ActiveRecord $activeRecord)
updateIndices(ActiveRecord $activeRecord)
updateDatabase(ActiveRecord $activeRecord)
update(ActiveRecord $activeRecord)
quote($value, string $type)
installDatabase(ActiveRecord $activeRecord, array $fields)
removeField(ActiveRecord $activeRecord, string $field_name)
truncateDatabase(ActiveRecord $activeRecord)
storeActiveRecordInCache(ActiveRecord $activeRecord)
Stores an active record into the Cache.
affectedRows(ActiveRecordList $activeRecordList)
nextID(ActiveRecord $activeRecord)
read(ActiveRecord $activeRecord)
__construct(private arConnector $arConnector)
ilGSStorageCache constructor.
resetDatabase(ActiveRecord $activeRecord)
checkConnection(ActiveRecord $activeRecord)
buildCacheKey(ActiveRecord $activeRecord)
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
nextID(ActiveRecord $activeRecord)
checkTableExists(ActiveRecord $activeRecord)
affectedRows(ActiveRecordList $activeRecordList)
checkConnection(ActiveRecord $activeRecord)
updateIndices(ActiveRecord $activeRecord)
truncateDatabase(ActiveRecord $activeRecord)
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)
create(ActiveRecord $activeRecord)
resetDatabase(ActiveRecord $activeRecord)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
updateDatabase(ActiveRecord $activeRecord)
delete(ActiveRecord $activeRecord)
readSet(ActiveRecordList $activeRecordList)
installDatabase(ActiveRecord $activeRecord, array $fields)
read(ActiveRecord $activeRecord)
removeField(ActiveRecord $activeRecord, string $field_name)
update(ActiveRecord $activeRecord)
quote(mixed $value, string $type)
$results
global $DIC
Definition: shib_login.php:26