Elgg  Version 5.1
EntityCache.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cache;
4 
10 class EntityCache {
11 
12  const MAX_SIZE = 256;
13 
17  protected $cache;
18 
22  protected $size = 0;
23 
29  public function __construct(BaseCache $cache) {
30  $this->cache = $cache;
31  }
32 
40  public function load(int $guid): ?\ElggEntity {
41  return $this->cache->load($guid);
42  }
43 
51  public function save(\ElggEntity $entity): void {
52  if (!$entity->guid || !$entity->isCacheable()) {
53  return;
54  }
55 
56  if ($this->size > self::MAX_SIZE) {
57  // Don't store too many or we'll have memory problems
58  return;
59  }
60 
61  $this->cache->save($entity->guid, $entity);
62  $this->size++;
63  }
64 
72  public function delete(int $guid): void {
73  if (!$guid) {
74  return;
75  }
76 
77  $entity = $this->cache->load($guid);
78  if (!$entity instanceof \ElggEntity) {
79  return;
80  }
81 
82  $this->cache->delete($guid);
83  $this->size--;
84  }
85 
91  public function clear(): void {
92  $this->cache->clear();
93  $this->size = 0;
94  }
95 }
save(\ElggEntity $entity)
Cache an entity.
Definition: EntityCache.php:51
__construct(BaseCache $cache)
Constructor.
Definition: EntityCache.php:29
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$entity
Definition: reset.php:8
Volatile cache for entities.
Definition: EntityCache.php:10
load(stdClass $row)
Loads attributes from the entities table into the object.
The Elgg cache base class.
Definition: BaseCache.php:9
clear()
Clear the entity cache.
Definition: EntityCache.php:91
load(int $guid)
Retrieve a entity from the cache.
Definition: EntityCache.php:40
isCacheable()
Is entity cacheable in the runtime cache.
$guid
Reset an ElggUpgrade.
Definition: reset.php:6