ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.CachedActiveRecord.php
Go to the documentation of this file.
1 <?php
2 
23 abstract 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  public function create(): void
72  {
73  parent::create();
74  }
75 
76  public function read(): void
77  {
78  parent::read();
79  $this->_hash = $this->buildHash();
80  }
81 
82  public function update(): void
83  {
84  if ($this->buildHash() !== $this->_hash) {
85  parent::update();
86  }
87  }
88 
89  public function delete(): void
90  {
91  parent::delete(); // TODO: Change the autogenerated stub
92  }
93 }
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...
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(mixed $primary_key=0, arConnector $arConnector=null)
__construct(VocabulariesInterface $vocabularies)
getConnectorContainerName()
Return the Name of your Connector Table
Class ilGSStorageCache.