ILIAS  release_8 Revision v8.24
class.arConnectorCache.php
Go to the documentation of this file.
1<?php
2
3/******************************************************************************
4 *
5 * This file is part of ILIAS, a powerful learning management system.
6 *
7 * ILIAS is licensed with the GPL-3.0, you should have received a copy
8 * of said license along with the source code.
9 *
10 * If this is not the case or you just want to try ILIAS, you'll find
11 * us at:
12 * https://www.ilias.de
13 * https://github.com/ILIAS-eLearning
14 *
15 *****************************************************************************/
21{
22 private \arConnector $arConnectorDB;
23 private \ilGlobalCache $cache;
24 public const CACHE_TTL_SECONDS = 180;
25
31 {
34 }
35
39 public function nextID(ActiveRecord $ar)
40 {
41 return $this->arConnectorDB->nextID($ar);
42 }
43
44 public function checkConnection(ActiveRecord $ar): bool
45 {
46 return $this->arConnectorDB->checkConnection($ar);
47 }
48
49 public function installDatabase(ActiveRecord $ar, array $fields): bool
50 {
51 return $this->arConnectorDB->installDatabase($ar, $fields);
52 }
53
54 public function updateDatabase(ActiveRecord $ar): bool
55 {
56 return $this->arConnectorDB->updateDatabase($ar);
57 }
58
59 public function resetDatabase(ActiveRecord $ar): bool
60 {
61 return $this->arConnectorDB->resetDatabase($ar);
62 }
63
64 public function truncateDatabase(ActiveRecord $ar): bool
65 {
66 return $this->arConnectorDB->truncateDatabase($ar);
67 }
68
69 public function checkTableExists(ActiveRecord $ar): bool
70 {
71 return $this->arConnectorDB->checkTableExists($ar);
72 }
73
74 public function checkFieldExists(ActiveRecord $ar, string $field_name): bool
75 {
76 return $this->arConnectorDB->checkFieldExists($ar, $field_name);
77 }
78
79 public function removeField(ActiveRecord $ar, string $field_name): bool
80 {
81 return $this->arConnectorDB->removeField($ar, $field_name);
82 }
83
84 public function renameField(ActiveRecord $ar, string $old_name, string $new_name): bool
85 {
86 return $this->arConnectorDB->renameField($ar, $old_name, $new_name);
87 }
88
89 public function create(ActiveRecord $ar): void
90 {
91 $this->arConnectorDB->create($ar);
92 $this->storeActiveRecordInCache($ar);
93 }
94
95 public function read(ActiveRecord $ar): array
96 {
97 if ($this->cache->isActive()) {
99 $cached_value = $this->cache->get($key);
100 if (is_array($cached_value)) {
101 return $cached_value;
102 }
103
104 if ($cached_value instanceof stdClass) {
105 return [$cached_value];
106 }
107 }
108
109 $results = $this->arConnectorDB->read($ar);
110
111 if ($this->cache->isActive()) {
113
114 $this->cache->set($key, $results, self::CACHE_TTL_SECONDS);
115 }
116
117 return $results;
118 }
119
120 public function update(ActiveRecord $ar): void
121 {
122 $this->arConnectorDB->update($ar);
123 $this->storeActiveRecordInCache($ar);
124 }
125
126 public function delete(ActiveRecord $ar): void
127 {
128 $this->arConnectorDB->delete($ar);
129
130 if ($this->cache->isActive()) {
131 $key = $ar->getConnectorContainerName() . "_" . $ar->getPrimaryFieldValue();
132 $this->cache->delete($key);
133 }
134 }
135
136 public function readSet(ActiveRecordList $arl): array
137 {
138 return $this->arConnectorDB->readSet($arl);
139 }
140
141 public function affectedRows(ActiveRecordList $arl): int
142 {
143 return $this->arConnectorDB->affectedRows($arl);
144 }
145
149 public function quote($value, string $type): string
150 {
151 return $this->arConnectorDB->quote($value, $type);
152 }
153
154 public function updateIndices(ActiveRecord $ar): void
155 {
156 $this->arConnectorDB->updateIndices($ar);
157 }
158
162 private function storeActiveRecordInCache(ActiveRecord $ar): void
163 {
164 if ($this->cache->isActive()) {
166 $value = $ar->asStdClass();
167
168 $this->cache->set($key, $value, self::CACHE_TTL_SECONDS);
169 }
170 }
171}
@noinspection NullPointerExceptionInspection
Class ActiveRecord.
getConnectorContainerName()
@description Return the Name of your Connector Table
Class ilGSStorageCache.
update(ActiveRecord $ar)
readSet(ActiveRecordList $arl)
quote($value, string $type)
nextID(ActiveRecord $ar)
storeActiveRecordInCache(ActiveRecord $ar)
Stores an active record into the Cache.
updateDatabase(ActiveRecord $ar)
read(ActiveRecord $ar)
installDatabase(ActiveRecord $ar, array $fields)
checkTableExists(ActiveRecord $ar)
checkConnection(ActiveRecord $ar)
truncateDatabase(ActiveRecord $ar)
renameField(ActiveRecord $ar, string $old_name, string $new_name)
resetDatabase(ActiveRecord $ar)
checkFieldExists(ActiveRecord $ar, string $field_name)
removeField(ActiveRecord $ar, string $field_name)
create(ActiveRecord $ar)
updateIndices(ActiveRecord $ar)
affectedRows(ActiveRecordList $arl)
__construct(arConnector $arConnectorDB)
ilGSStorageCache constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
nextID(ActiveRecord $activeRecord)
installDatabase(ActiveRecord $activeRecord, array $fields)
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)
removeField(ActiveRecord $activeRecord, string $field_name)
quote($value, string $type)
update(ActiveRecord $activeRecord)
affectedRows(ActiveRecordList $activeRecordList)
checkTableExists(ActiveRecord $activeRecord)
truncateDatabase(ActiveRecord $activeRecord)
checkConnection(ActiveRecord $activeRecord)
create(ActiveRecord $activeRecord)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
resetDatabase(ActiveRecord $activeRecord)
updateIndices(ActiveRecord $activeRecord)
updateDatabase(ActiveRecord $activeRecord)
read(ActiveRecord $activeRecord)
delete(ActiveRecord $activeRecord)
readSet(ActiveRecordList $activeRecordList)
Class arConnector.
static getInstance(?string $component)
string $key
Consumer key/client ID value.
Definition: System.php:193
$type
$results