ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.CachedActiveRecord.php
Go to the documentation of this file.
1<?php
2
23abstract class CachedActiveRecord extends ActiveRecord
24{
25 private string $_hash = '';
26
27 final public function getCacheIdentifier(): string
28 {
29 if ($this->getArFieldList()->getPrimaryField()) {
30 return ($this->getConnectorContainerName() . "_" . $this->getPrimaryFieldValue());
31 }
32
33 return "";
34 }
35
36 public function getTTL(): int
37 {
38 return 60;
39 }
40
44 public function __construct(mixed $primary_key = 0, ?arConnector $arConnector = null)
45 {
46 if (is_null($arConnector)) {
47 $arConnector = new arConnectorDB();
48 }
49
50 $arConnector = new arConnectorCache($arConnector);
51 arConnectorMap::register($this, $arConnector);
52 parent::__construct($primary_key);
53 }
54
55 public function afterObjectLoad(): void
56 {
57 parent::afterObjectLoad();
58 $this->_hash = $this->buildHash();
59 }
60
61 private function buildHash(): string
62 {
63 $hashing = [];
64 foreach ($this->getArFieldList()->getFields() as $arField) {
65 $name = $arField->getName();
66 $hashing[$name] = $this->{$name};
67 }
68 return md5(serialize($hashing));
69 }
70
71 #[\Override]
72 public function create(): void
73 {
74 parent::create();
75 }
76
77 #[\Override]
78 public function read(): void
79 {
80 parent::read();
81 $this->_hash = $this->buildHash();
82 }
83
84 #[\Override]
85 public function update(): void
86 {
87 if ($this->buildHash() !== $this->_hash) {
88 parent::update();
89 }
90 }
91
92 #[\Override]
93 public function delete(): void
94 {
95 parent::delete(); // TODO: Change the autogenerated stub
96 }
97}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(mixed $primary_key=0, ?arConnector $arConnector=null)
@inheritDoc
Class ilGSStorageCache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static register(ActiveRecord $activeRecord, arConnector $arConnector)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc