aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector/Sabre/CachingTree.php
blob: a715991fcf67b8660b120c629d05a5fd5b5803f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
 * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\DAV\Connector\Sabre;

use Sabre\DAV\Tree;

class CachingTree extends Tree {
	/**
	 * Store a node in the cache
	 */
	public function cacheNode(Node $node, ?string $path = null): void {
		if (is_null($path)) {
			$path = $node->getPath();
		}
		$this->cache[trim($path, '/')] = $node;
	}

	/**
	 * @param string $path
	 * @return void
	 */
	public function markDirty($path) {
		// We don't care enough about sub-paths
		// flushing the entire cache
		$path = trim($path, '/');
		foreach ($this->cache as $nodePath => $node) {
			$nodePath = (string) $nodePath;
			if ($path === '' || $nodePath == $path || str_starts_with($nodePath, $path . '/')) {
				unset($this->cache[$nodePath]);
			}
		}
	}
}