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 DateInterval;
6
use Psr\SimpleCache\CacheInterface;
7
 
8
/**
9
 * This is the default implementation for in-memory cell collection.
10
 *
11
 * Alternative implementation should leverage off-memory, non-volatile storage
12
 * to reduce overall memory usage.
13
 */
14
class SimpleCache3 implements CacheInterface
15
{
16
    private array $cache = [];
17
 
18
    public function clear(): bool
19
    {
20
        $this->cache = [];
21
 
22
        return true;
23
    }
24
 
25
    public function delete(string $key): bool
26
    {
27
        unset($this->cache[$key]);
28
 
29
        return true;
30
    }
31
 
32
    public function deleteMultiple(iterable $keys): bool
33
    {
34
        foreach ($keys as $key) {
35
            $this->delete($key);
36
        }
37
 
38
        return true;
39
    }
40
 
41
    public function get(string $key, mixed $default = null): mixed
42
    {
43
        if ($this->has($key)) {
44
            return $this->cache[$key];
45
        }
46
 
47
        return $default;
48
    }
49
 
50
    public function getMultiple(iterable $keys, mixed $default = null): iterable
51
    {
52
        $results = [];
53
        foreach ($keys as $key) {
54
            $results[$key] = $this->get($key, $default);
55
        }
56
 
57
        return $results;
58
    }
59
 
60
    public function has(string $key): bool
61
    {
62
        return array_key_exists($key, $this->cache);
63
    }
64
 
65
    public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
66
    {
67
        $this->cache[$key] = $value;
68
 
69
        return true;
70
    }
71
 
72
    public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
73
    {
74
        foreach ($values as $key => $value) {
75
            $this->set($key, $value);
76
        }
77
 
78
        return true;
79
    }
80
}