Elgg  Version master
QueryCache.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cache;
4 
5 use Elgg\Config;
6 
12 class QueryCache extends CacheService {
13 
14  protected int $query_cache_limit = 50;
15 
16  protected array $keys = [];
17 
23  public function __construct(protected Config $config) {
25 
26  $this->cache = new CompositeCache('query_cache', $this->config, $flags);
27 
28  $this->enabled = $this->config->db_disable_query_cache !== true;
29  if (isset($this->config->db_query_cache_limit)) {
30  $this->query_cache_limit = (int) $this->config->db_query_cache_limit;
31  }
32  }
33 
37  public function purge(): void {
38  $this->keys = [];
39 
40  parent::purge();
41  }
42 
46  public function invalidate(): void {
47  $this->keys = [];
48 
49  parent::invalidate();
50  }
51 
55  public function clear(): void {
56  $this->keys = [];
57 
58  parent::clear();
59  }
60 
64  public function save(string $key, mixed $data, int|\DateTime $expire_after = null): bool {
65  $result = parent::save($key, $data, $expire_after);
66  if ($result && !isset($this->keys[$key])) {
67  $this->keys[$key] = true;
68 
69  if (count($this->keys) > $this->query_cache_limit) {
70  $this->delete(array_key_first($this->keys));
71  }
72  }
73 
74  return $result;
75  }
76 
80  public function load(string $key): mixed {
81  if (isset($this->keys[$key])) {
82  // when used move key to bottom
83  unset($this->keys[$key]);
84  $this->keys[$key] = true;
85  }
86 
87  return parent::load($key);
88  }
89 
93  public function delete(string $key): bool {
94  unset($this->keys[$key]);
95 
96  return parent::delete($key);
97  }
98 }
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
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
Composite cache pool.
__construct(protected Config $config)
Constructor.
Definition: QueryCache.php:23
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
save(string $key, mixed $data, int|\DateTime $expire_after=null)
{}
Definition: QueryCache.php:64
Volatile cache for select queries.
Definition: QueryCache.php:12
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
Extension of the DateTime class to support formatting a date using the locale.
Definition: DateTime.php:12
load(string $key)
{}
Definition: QueryCache.php:80