ILIAS  release_8 Revision v8.24
class.CachedActiveRecord.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 *****************************************************************************/
20abstract class CachedActiveRecord extends ActiveRecord
21{
22 private string $_hash = '';
23
24 abstract public function getCache(): ilGlobalCache;
25
26 final public function getCacheIdentifier(): string
27 {
28 if ($this->getArFieldList()->getPrimaryField()) {
29 return ($this->getConnectorContainerName() . "_" . $this->getPrimaryFieldValue());
30 }
31
32 return "";
33 }
34
35 public function getTTL(): int
36 {
37 return 60;
38 }
39
43 public function __construct($primary_key = 0, arConnector $connector = null)
44 {
45 if (is_null($connector)) {
46 $connector = new arConnectorDB();
47 }
48
49 $connector = new arConnectorCache($connector);
50 arConnectorMap::register($this, $connector);
51 parent::__construct($primary_key);
52 }
53
54 public function afterObjectLoad(): void
55 {
56 parent::afterObjectLoad();
57 $this->_hash = $this->buildHash();
58 }
59
60 private function buildHash(): string
61 {
62 $hashing = [];
63 foreach ($this->getArFieldList()->getFields() as $field) {
64 $name = $field->getName();
65 $hashing[$name] = $this->{$name};
66 }
67 return md5(serialize($hashing));
68 }
69
70 public function create(): void
71 {
72 $this->getCache()->flush();
73 parent::create();
74 }
75
79 public function copy(int $new_id = 0): \ActiveRecord
80 {
81 $this->getCache()->flush();
82 return parent::copy($new_id);
83 }
84
85 public function read(): void
86 {
87 parent::read();
88 $this->_hash = $this->buildHash();
89 }
90
91 public function update()
92 {
93 if ($this->buildHash() !== $this->_hash) {
94 $this->getCache()->flush();
95 parent::update();
96 }
97 }
98
99 public function delete()
100 {
101 $this->getCache()->flush();
102 parent::delete(); // TODO: Change the autogenerated stub
103 }
104}
Class ActiveRecord.
getConnectorContainerName()
@description Return the Name of your Connector Table
Class CachedActiveRecord.
__construct($primary_key=0, arConnector $connector=null)
@inheritDoc
copy(int $new_id=0)
@inheritDoc
Class ilGSStorageCache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static register(ActiveRecord $ar, arConnector $connector)
Class arConnector.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc