You are here

protected function S3fsStream::deleteCache in S3 File System 4.0.x

Same name and namespace in other branches
  1. 8.3 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::deleteCache()

Delete an object's metadata from the cache.

Parameters

mixed $uri: A string (or array of strings) containing the URI(s) of the object(s) to be deleted.

Throws

\Drupal\s3fs\S3fsException Exceptions which occur in the database call will percolate.

3 calls to S3fsStream::deleteCache()
S3fsStream::rename in src/StreamWrapper/S3fsStream.php
Support for rename().
S3fsStream::rmdir in src/StreamWrapper/S3fsStream.php
Support for rmdir().
S3fsStream::unlink in src/StreamWrapper/S3fsStream.php
Support for unlink().

File

src/StreamWrapper/S3fsStream.php, line 1383

Class

S3fsStream
Defines a Drupal s3 (s3://) stream wrapper class.

Namespace

Drupal\s3fs\StreamWrapper

Code

protected function deleteCache($uri) {
  if (!is_array($uri)) {
    $uri = [
      $uri,
    ];
  }
  $cids = [];

  // Build an OR query to delete all the URIs at once.
  $delete_query = \Drupal::database()
    ->delete('s3fs_file');
  $or = $delete_query
    ->orConditionGroup();
  foreach ($uri as $u) {
    $or
      ->condition('uri', $u, '=');

    // Add URI to cids to be cleared from the Drupal cache.
    $cids[] = S3FS_CACHE_PREFIX . $u;
  }

  // Clear URIs from the Drupal cache.
  $cache = \Drupal::cache(S3FS_CACHE_BIN);
  $cache
    ->deleteMultiple($cids);
  $delete_query
    ->condition($or);
  return $delete_query
    ->execute();
}