ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.arObjectCache.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected static array $cache = array();
27 
32  public static function isCached($class, $id): bool
33  {
34  if (!isset(self::$cache[$class])) {
35  return false;
36  }
37  if (!isset(self::$cache[$class][$id]) || !self::$cache[$class][$id] instanceof ActiveRecord) {
38  return false;
39  }
40 
41  return array_key_exists($id, self::$cache[$class]);
42  }
43 
44  public static function store(ActiveRecord $object): void
45  {
46  if (!isset($object->is_new)) {
47  self::$cache[get_class($object)][$object->getPrimaryFieldValue()] = $object;
48  }
49  }
50 
51  public static function printStats(): void
52  {
53  foreach (self::$cache as $class => $objects) {
54  echo $class;
55  echo ": ";
56  echo count($objects);
57  echo " Objects<br>";
58  }
59  }
60 
66  public static function get($class, $id): \ActiveRecord
67  {
68  $instance = new $class();
69  if (!self::isCached($class, $id)) {
70  throw new arException(arException::GET_UNCACHED_OBJECT, $class . ': ' . $id);
71  }
72 
73  return self::$cache[$class][$id];
74  }
75 
76  public static function purge(ActiveRecord $object): void
77  {
78  unset(self::$cache[get_class($object)][$object->getPrimaryFieldValue()]);
79  }
80 
84  public static function flush($class_name): void
85  {
86  if ($class_name instanceof ActiveRecord) {
87  $class_name = get_class($class_name);
88  }
89  unset(self::$cache[$class_name]);
90  }
91 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const GET_UNCACHED_OBJECT
static purge(ActiveRecord $object)
static store(ActiveRecord $object)
static flush($class_name)
static isCached($class, $id)
Class arException.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static array $cache