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

nette / caching / 22226743054

20 Feb 2026 01:53PM UTC coverage: 88.227% (+1.0%) from 87.202%
22226743054

Pull #85

github

web-flow
Merge c3f6b576c into f6698ea58
Pull Request #85: Extend MemoryStorage with Tags, Priority, Expire and Sliding modifiers

35 of 36 new or added lines in 1 file covered. (97.22%)

57 existing lines in 7 files now uncovered.

622 of 705 relevant lines covered (88.23%)

0.88 hits per line

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

83.87
/src/Bridges/CacheLatte/Runtime.php
1
<?php
2

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

8
declare(strict_types=1);
9

10
namespace Nette\Bridges\CacheLatte;
11

12
use Latte;
13
use Nette;
14
use Nette\Caching\Cache;
15
use Nette\Caching\OutputHelper;
16
use function array_intersect_key, array_key_exists, array_merge, array_pop, count, end, is_file, range;
17

18

19
/**
20
 * Runtime helpers for Latte v3.
21
 * @internal
22
 */
23
class Runtime
24
{
25
        /** @var array<int, OutputHelper|\stdClass> */
26
        private array $stack = [];
27

28

29
        public function __construct(
1✔
30
                private readonly Nette\Caching\Storage $storage,
31
        ) {
32
        }
1✔
33

34

35
        public function initialize(Latte\Runtime\Template $template): void
1✔
36
        {
37
                if ($this->stack) {
1✔
38
                        $file = (new \ReflectionClass($template))->getFileName();
1✔
39
                        if (@is_file($file)) { // @ - may trigger error
1✔
40
                                end($this->stack)->dependencies[Cache::Files][] = $file;
1✔
41
                        }
42
                }
43
        }
1✔
44

45

46
        /**
47
         * Starts the output cache. Returns true if buffering was started.
48
         * @param array<string, mixed>|null $args {if?: bool, tags?: string[], expire?: string, expiration?: string, dependencies?: callable}
49
         */
50
        public function createCache(string $key, ?array $args = null): bool
1✔
51
        {
52
                if ($args) {
1✔
53
                        if (array_key_exists('if', $args) && !$args['if']) {
1✔
UNCOV
54
                                $this->stack[] = new \stdClass;
×
55
                                return true;
×
56
                        }
57

58
                        $key = array_merge([$key], array_intersect_key($args, range(0, count($args))));
1✔
59
                }
60

61
                if ($this->stack) {
1✔
62
                        end($this->stack)->dependencies[Cache::Items][] = $key;
1✔
63
                }
64

65
                $cache = new Cache($this->storage, 'Nette.Templating.Cache');
1✔
66
                if ($helper = $cache->capture($key)) {
1✔
67
                        $this->stack[] = $helper;
1✔
68

69
                        if (isset($args['dependencies'])) {
1✔
70
                                $args += $args['dependencies']();
1✔
71
                        }
72

73
                        $helper->dependencies[Cache::Tags] = $args['tags'] ?? null;
1✔
74
                        $helper->dependencies[Cache::Expire] = $args['expiration'] ?? $args['expire'] ?? '+ 7 days';
1✔
75
                }
76

77
                return (bool) $helper;
1✔
78
        }
79

80

81
        /**
82
         * Ends the output cache.
83
         */
84
        public function end(): void
85
        {
86
                $helper = array_pop($this->stack);
1✔
87
                if ($helper instanceof OutputHelper) {
1✔
88
                        $helper->end();
1✔
89
                }
90
        }
1✔
91

92

93
        public function rollback(): void
94
        {
UNCOV
95
                $helper = array_pop($this->stack);
×
96
                if ($helper instanceof OutputHelper) {
×
97
                        $helper->rollback();
×
98
                }
99
        }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc