ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMemcacheNodesRepository.php
Go to the documentation of this file.
1<?php
2
21
23{
24 public const TABLE_NAME = "il_gc_memcache_server";
25
26 public function __construct(private ?ilDBInterface $db = null)
27 {
28 }
29
30 public function deleteAll(): void
31 {
32 if ($this->db === null) {
33 return;
34 }
35 $this->db->manipulate("TRUNCATE TABLE " . self::TABLE_NAME);
36 }
37
38 public function store(Node $node): Node
39 {
40 if ($this->db === null) {
41 return $node;
42 }
43 $this->create(
44 $node->getHost(),
45 $node->getPort(),
46 $node->getWeight()
47 );
48 return $node;
49 }
50
51 public function create(
52 string $host,
53 int $port,
54 int $weight
55 ): Node {
56 $node = new Node($host, $port, $weight);
57 if ($this->db != null) {
58 $next_id = $this->db->nextId(self::TABLE_NAME);
59 $this->db->insert(self::TABLE_NAME, [
60 "id" => ["integer", $next_id],
61 "status" => ["integer", true],
62 "host" => ["text", $node->getHost()],
63 "port" => ["integer", $node->getPort()],
64 "weight" => ["integer", $node->getWeight()],
65 "flush_needed" => ["integer", false]
66 ]);
67 }
68 return $node;
69 }
70
71 public function getNodes(): array
72 {
73 if ($this->db === null) {
74 return [];
75 }
76 $set = $this->db->query("SELECT * FROM " . self::TABLE_NAME);
77 $nodes = [];
78 while ($rec = $this->db->fetchAssoc($set)) {
79 $nodes[] = new Node(
80 $rec["host"],
81 (int) $rec["port"],
82 (int) $rec["weight"]
83 );
84 }
85 return $nodes;
86 }
87}
create(string $host, int $port, int $weight)
__construct(private ?ilDBInterface $db=null)
Interface ilDBInterface.