1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Modules\Cli\Tasks; |
13
|
|
|
|
14
|
|
|
use Phalcon\Cache\Exception\InvalidArgumentException; |
15
|
|
|
use Zemit\Modules\Cli\Task; |
16
|
|
|
|
17
|
|
|
class CacheTask extends Task |
18
|
|
|
{ |
19
|
|
|
public string $cliDoc = <<<DOC |
20
|
|
|
Usage: |
21
|
|
|
zemit cli cache clear |
22
|
|
|
zemit cli cache has <key> |
23
|
|
|
zemit cli cache delete <key> |
24
|
|
|
zemit cli cache delete-multiple [<key>...] |
25
|
|
|
|
26
|
|
|
DOC; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Clears all items from the cache. |
30
|
|
|
* |
31
|
|
|
* @return bool True if all items were successfully cleared, false otherwise. |
32
|
|
|
*/ |
33
|
|
|
public function clearAction(): bool |
34
|
|
|
{ |
35
|
|
|
return $this->cache->clear(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Checks if the given action key exists in the cache. |
40
|
|
|
* |
41
|
|
|
* @param string $key The key identifying the action in the cache. |
42
|
|
|
* @return bool Returns true if the action key exists in the cache, false otherwise. |
43
|
|
|
* @throws InvalidArgumentException |
44
|
|
|
*/ |
45
|
|
|
public function hasAction(string $key): bool |
46
|
|
|
{ |
47
|
|
|
return $this->cache->has($key); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Deletes an item from the cache. |
52
|
|
|
* |
53
|
|
|
* @param string $key The key of the item to be deleted. |
54
|
|
|
* @return bool True if the item was successfully deleted, false otherwise. |
55
|
|
|
* @throws InvalidArgumentException |
56
|
|
|
*/ |
57
|
|
|
public function deleteAction(string $key): bool |
58
|
|
|
{ |
59
|
|
|
return $this->cache->delete($key); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Deletes multiple cache entries specified by the given keys. |
64
|
|
|
* |
65
|
|
|
* @param mixed ...$keys A variable number of keys representing the cache entries to be deleted. |
66
|
|
|
* |
67
|
|
|
* @return bool Returns true if all cache entries were successfully deleted, false otherwise. |
68
|
|
|
*/ |
69
|
|
|
public function deleteMultipleAction(string ...$keys): bool |
70
|
|
|
{ |
71
|
|
|
return $this->cache->deleteMultiple($keys); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|