ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.CachedActiveRecord.php
Go to the documentation of this file.
1 <?php
2 
7 abstract class CachedActiveRecord extends ActiveRecord implements arStorageInterface
8 {
12  private $_hash = '';
13 
17  abstract public function getCache() : ilGlobalCache;
18 
22  final public function getCacheIdentifier() : string
23  {
24  if ($this->getArFieldList()->getPrimaryField()) {
25  return ($this->getConnectorContainerName() . "_" . $this->getPrimaryFieldValue());
26  }
27 
28  return "";
29  }
30 
31  public function getTTL() : int
32  {
33  return 60;
34  }
35 
39  public function __construct($primary_key = 0, arConnector $connector = null)
40  {
41  if (is_null($connector)) {
42  $connector = new arConnectorDB();
43  }
44 
45  $connector = new arConnectorCache($connector);
46  arConnectorMap::register($this, $connector);
47  parent::__construct($primary_key, $connector);
48  }
49 
50  public function afterObjectLoad()
51  {
52  parent::afterObjectLoad();
53  $this->_hash = $this->buildHash();
54  }
55 
56  private function buildHash() : string
57  {
58  $hashing = [];
59  foreach ($this->getArFieldList()->getFields() as $field) {
60  $name = $field->getName();
61  $hashing[$name] = $this->{$name};
62  }
63  return md5(serialize($hashing));
64  }
65 
66  public function storeObjectToCache()
67  {
68  parent::storeObjectToCache();
69  }
70 
74  public function buildFromArray(array $array)
75  {
76  return parent::buildFromArray($array);
77  }
78 
79  public function store()
80  {
81  parent::store();
82  }
83 
84  public function save()
85  {
86  parent::save();
87  }
88 
89  public function create()
90  {
91  $this->getCache()->flush();
92  parent::create();
93  }
94 
98  public function copy($new_id = 0)
99  {
100  $this->getCache()->flush();
101  return parent::copy($new_id);
102  }
103 
104  public function read()
105  {
106  parent::read();
107  }
108 
109  public function update()
110  {
111  if ($this->buildHash() !== $this->_hash) {
112  $this->getCache()->flush();
113  parent::update();
114  }
115  }
116 
117  public function delete()
118  {
119  $this->getCache()->flush();
120  parent::delete(); // TODO: Change the autogenerated stub
121  }
122 
126  public static function find($primary_key, array $add_constructor_args = array())
127  {
128  return parent::find($primary_key, $add_constructor_args);
129  }
130 
134  public static function connector(arConnector $connector)
135  {
136  return parent::connector($connector); // TODO: Change the autogenerated stub
137  }
138 }
Class arStorageInterface.
static find($primary_key, array $add_constructor_args=array())
Class CachedActiveRecord.
Class arConnectorDB.
Class ActiveRecord.
static register(ActiveRecord $ar, arConnector $connector)
__construct($primary_key=0, arConnector $connector=null)
Class arConnector.
Class ilGSStorageCache.
update($pash, $contents, Config $config)
static connector(arConnector $connector)