CachingTree.php 845 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Connector\Sabre;
  7. use Sabre\DAV\Tree;
  8. class CachingTree extends Tree {
  9. /**
  10. * Store a node in the cache
  11. */
  12. public function cacheNode(Node $node, ?string $path = null): void {
  13. if (is_null($path)) {
  14. $path = $node->getPath();
  15. }
  16. $this->cache[trim($path, '/')] = $node;
  17. }
  18. /**
  19. * @param string $path
  20. * @return void
  21. */
  22. public function markDirty($path) {
  23. // We don't care enough about sub-paths
  24. // flushing the entire cache
  25. $path = trim($path, '/');
  26. foreach ($this->cache as $nodePath => $node) {
  27. $nodePath = (string)$nodePath;
  28. if ($path === '' || $nodePath == $path || str_starts_with($nodePath, $path . '/')) {
  29. unset($this->cache[$nodePath]);
  30. }
  31. }
  32. }
  33. }