• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / caching / 20835633737

08 Jan 2026 11:36PM UTC coverage: 87.407%. Remained the same
20835633737

push

github

dg
added CLAUDE.md

590 of 675 relevant lines covered (87.41%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.56
/src/Bridges/Psr/PsrCacheAdapter.php
1
<?php
2

3
/**
4
 * This file is part of the Tracy (https://tracy.nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Bridges\Psr;
11

12
use DateInterval;
13
use Nette;
14
use Psr;
15

16

17
class PsrCacheAdapter implements Psr\SimpleCache\CacheInterface
18
{
19
        public function __construct(
1✔
20
                private readonly Nette\Caching\Storage $storage,
21
        ) {
22
        }
1✔
23

24

25
        public function get(string $key, mixed $default = null): mixed
1✔
26
        {
27
                return $this->storage->read($key) ?? $default;
1✔
28
        }
29

30

31
        public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
1✔
32
        {
33
                $dependencies = [];
1✔
34
                if ($ttl !== null) {
1✔
35
                        $dependencies[Nette\Caching\Cache::Expire] = self::ttlToSeconds($ttl);
1✔
36
                }
37

38
                $this->storage->write($key, $value, $dependencies);
1✔
39

40
                return true;
1✔
41
        }
42

43

44
        public function delete(string $key): bool
45
        {
46
                $this->storage->remove($key);
×
47
                return true;
×
48
        }
49

50

51
        public function clear(): bool
52
        {
53
                $this->storage->clean([Nette\Caching\Cache::All => true]);
×
54
                return true;
×
55
        }
56

57

58
        /**
59
         * @return \Generator<string, mixed>
60
         */
61
        public function getMultiple(iterable $keys, mixed $default = null): \Generator
1✔
62
        {
63
                foreach ($keys as $name) {
1✔
64
                        yield $name => $this->get($name, $default);
1✔
65
                }
66
        }
1✔
67

68

69
        /**
70
         * @param iterable<string|int, mixed> $values
71
         */
72
        public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
1✔
73
        {
74
                $ttl = self::ttlToSeconds($ttl);
1✔
75

76
                foreach ($values as $key => $value) {
1✔
77
                        $this->set((string) $key, $value, $ttl);
1✔
78
                }
79

80
                return true;
1✔
81
        }
82

83

84
        /** @param  iterable<string>  $keys */
85
        public function deleteMultiple(iterable $keys): bool
86
        {
87
                foreach ($keys as $value) {
×
88
                        $this->delete($value);
×
89
                }
90

91
                return true;
×
92
        }
93

94

95
        public function has(string $key): bool
1✔
96
        {
97
                return $this->storage->read($key) !== null;
1✔
98
        }
99

100

101
        private static function ttlToSeconds(null|int|DateInterval $ttl = null): ?int
1✔
102
        {
103
                if ($ttl instanceof DateInterval) {
1✔
104
                        return self::dateIntervalToSeconds($ttl);
1✔
105
                }
106

107
                return $ttl;
1✔
108
        }
109

110

111
        private static function dateIntervalToSeconds(DateInterval $dateInterval): int
1✔
112
        {
113
                $now = new \DateTimeImmutable;
1✔
114
                $expiresAt = $now->add($dateInterval);
1✔
115
                return $expiresAt->getTimestamp() - $now->getTimestamp();
1✔
116
        }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc