Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Collection\Memory;
4
 
5
use Psr\SimpleCache\CacheInterface;
6
 
7
/**
8
 * This is the default implementation for in-memory cell collection.
9
 *
10
 * Alternative implementation should leverage off-memory, non-volatile storage
11
 * to reduce overall memory usage.
12
 *
13
 * Either SimpleCache1 or SimpleCache3, but not both, may be used.
14
 * For code coverage testing, it will always be SimpleCache3.
15
 *
16
 * @codeCoverageIgnore
17
 */
18
class SimpleCache1 implements CacheInterface
19
{
20
    /**
21
     * @var array Cell Cache
22
     */
23
    private array $cache = [];
24
 
25
    public function clear(): bool
26
    {
27
        $this->cache = [];
28
 
29
        return true;
30
    }
31
 
32
    public function delete($key): bool
33
    {
34
        unset($this->cache[$key]);
35
 
36
        return true;
37
    }
38
 
39
    public function deleteMultiple($keys): bool
40
    {
41
        foreach ($keys as $key) {
42
            $this->delete($key);
43
        }
44
 
45
        return true;
46
    }
47
 
48
    public function get($key, $default = null): mixed
49
    {
50
        if ($this->has($key)) {
51
            return $this->cache[$key];
52
        }
53
 
54
        return $default;
55
    }
56
 
57
    public function getMultiple($keys, $default = null): iterable
58
    {
59
        $results = [];
60
        foreach ($keys as $key) {
61
            $results[$key] = $this->get($key, $default);
62
        }
63
 
64
        return $results;
65
    }
66
 
67
    public function has($key): bool
68
    {
69
        return array_key_exists($key, $this->cache);
70
    }
71
 
72
    public function set($key, $value, $ttl = null): bool
73
    {
74
        $this->cache[$key] = $value;
75
 
76
        return true;
77
    }
78
 
79
    public function setMultiple($values, $ttl = null): bool
80
    {
81
        foreach ($values as $key => $value) {
82
            $this->set($key, $value);
83
        }
84
 
85
        return true;
86
    }
87
}