Cache

class OC\Files\Cache\Cache
Metadata cache for a storage
The cache stores the metadata for all files and folders in a storage and is kept up to date trough the following mechanisms:

- Scanner: scans the storage and updates the cache where needed
- Watcher: checks for changes made to the filesystem outside of the ownCloud instance and rescans files and folder when a change is detected
- Updater: listens to changes made to the filesystem inside of the ownCloud instance and updates the cache where needed
- ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater
Source:lib/private/Files/Cache/Cache.php#69
Implements:OCP\Files\Cache\ICache
Used traits:OC\Files\Cache\MoveFromCacheTrait

Properties

protected static property OC\Files\Cache\Cache::$partial
Source:lib/private/Files/Cache/Cache.php#77
Type:array partial data for the cache
protected static property OC\Files\Cache\Cache::$storageId
Source:lib/private/Files/Cache/Cache.php#82
Type:string
protected static property OC\Files\Cache\Cache::$storageCache
Source:lib/private/Files/Cache/Cache.php#89
Type:\OC\Files\Cache\Storage
protected static property OC\Files\Cache\Cache::$mimetypeLoader
Source:lib/private/Files/Cache/Cache.php#92
Type:\OCP\Files\IMimeTypeLoader
protected static property OC\Files\Cache\Cache::$connection
Source:lib/private/Files/Cache/Cache.php#97
Type:\OCP\IDBConnection
protected static property OC\Files\Cache\Cache::$eventDispatcher
Source:lib/private/Files/Cache/Cache.php#102
Type:\OCP\EventDispatcher\IEventDispatcher
protected static property OC\Files\Cache\Cache::$querySearchHelper
Source:lib/private/Files/Cache/Cache.php#105
Type:\OC\Files\Cache\QuerySearchHelper

Methods

public OC\Files\Cache\Cache::__construct($storage)
Source:

lib/private/Files/Cache/Cache.php#110

Parameters:
protected OC\Files\Cache\Cache::getQueryBuilder()
Source:lib/private/Files/Cache/Cache.php#124
public OC\Files\Cache\Cache::getNumericStorageId()
Get the numeric storage id for this cache’s storage
Source:lib/private/Files/Cache/Cache.php#138
Returns:int
public OC\Files\Cache\Cache::get($file)
get the stored metadata of a file or folder
Source:lib/private/Files/Cache/Cache.php#148
Parameters:
Returns:\OCP\Files\Cache\ICacheEntry | bool the cache entry as array of false if the file is not found in the cache
public static OC\Files\Cache\Cache::cacheEntryFromData($data, $mimetypeLoader)
Create a CacheEntry from database row
Source:

lib/private/Files/Cache/Cache.php#183

Parameters:
Returns:

\OC\Files\Cache\CacheEntry

public OC\Files\Cache\Cache::getFolderContents($folder)
get the metadata of all files stored in $folder
Source:

lib/private/Files/Cache/Cache.php#215

Parameters:
  • $folder (string)
Returns:

\OCP\Files\Cache\ICacheEntry[]

public OC\Files\Cache\Cache::getFolderContentsById($fileId)
get the metadata of all files stored in $folder
Source:

lib/private/Files/Cache/Cache.php#226

Parameters:
  • $fileId (int) the file id of the folder
Returns:

\OCP\Files\Cache\ICacheEntry[]

public OC\Files\Cache\Cache::put($file, $data)
insert or update meta data for a file or folder
Source:

lib/private/Files/Cache/Cache.php#253

Parameters:
  • $file (string)
  • $data (array)
Returns:

int file id

Throws:

\RuntimeException

public OC\Files\Cache\Cache::insert($file, $data)
insert meta data for a new file or folder
Source:

lib/private/Files/Cache/Cache.php#271

Parameters:
  • $file (string)
  • $data (array)
Returns:

int file id

Throws:

\RuntimeException

public OC\Files\Cache\Cache::update($id, $data)
update the metadata of an existing file or folder in the cache
Source:

lib/private/Files/Cache/Cache.php#348

Parameters:
  • $id (int) the fileid of the existing file or folder
  • $data (array) [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged
protected OC\Files\Cache\Cache::normalizeData($data)
extract query parts and params array from data array
Source:

lib/private/Files/Cache/Cache.php#425

Parameters:
  • $data (array)
Returns:

array

public OC\Files\Cache\Cache::getId($file)
get the file id for a file
A file id is a numeric id for a file or folder that’s unique within an owncloud instance which stays the same for the lifetime of a file

File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing
Source:

lib/private/Files/Cache/Cache.php#478

Parameters:
  • $file (string)
Returns:

int

public OC\Files\Cache\Cache::getParentId($file)
get the id of the parent folder of a file
Source:

lib/private/Files/Cache/Cache.php#501

Parameters:
  • $file (string)
Returns:

int

public OC\Files\Cache\Cache::inCache($file)
check if a file is available in the cache
Source:

lib/private/Files/Cache/Cache.php#524

Parameters:
  • $file (string)
Returns:

bool

public OC\Files\Cache\Cache::remove($file)
remove a file or folder from the cache
when removing a folder from the cache all files and folders inside the folder will be removed as well
Source:

lib/private/Files/Cache/Cache.php#535

Parameters:
  • $file (string)
public OC\Files\Cache\Cache::move($source, $target)
Move a file or folder in the cache
Source:

lib/private/Files/Cache/Cache.php#615

Parameters:
  • $source (string)
  • $target (string)
protected OC\Files\Cache\Cache::getMoveInfo($path)
Get the storage id and path needed for a move
Source:

lib/private/Files/Cache/Cache.php#625

Parameters:
  • $path (string)
Returns:

array [$storageId, $internalPath]

public OC\Files\Cache\Cache::moveFromCache($sourceCache, $sourcePath, $targetPath)
Move a file or folder in the cache
Source:

lib/private/Files/Cache/Cache.php#638

Parameters:
Throws:

\OC\DatabaseException

Throws:

\Exception if the given storages have an invalid id

Throws:

\OC\DatabaseException

Throws:

\Exception if the given storages have an invalid id

public OC\Files\Cache\Cache::clear()
remove all entries for files that are stored on the storage from the cache
Source:lib/private/Files/Cache/Cache.php#718
public OC\Files\Cache\Cache::getStatus($file)
Get the scan status of a file
- Cache::NOT_FOUND: File is not in the cache
- Cache::PARTIAL: File is not stored in the cache but some incomplete data is known
- Cache::SHALLOW: The folder and it’s direct children are in the cache but not all sub folders are fully scanned
- Cache::COMPLETE: The file or folder, with all it’s children) are fully scanned
Source:

lib/private/Files/Cache/Cache.php#742

Parameters:
  • $file (string)
Returns:

int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE

public OC\Files\Cache\Cache::search($pattern)
search for files matching $pattern
Source:

lib/private/Files/Cache/Cache.php#777

Parameters:
  • $pattern (string) the search pattern using SQL search syntax (e.g. ‘%searchstring%’)
Returns:

\OCP\Files\Cache\ICacheEntry[] an array of cache entries where the name matches the search pattern

public OC\Files\Cache\Cache::searchByMime($mimetype)
search for files by mimetype
Source:

lib/private/Files/Cache/Cache.php#818

Parameters:
  • $mimetype (string) either a full mimetype to search (‘text/plain’) or only the first part of a mimetype (‘image’)

where it will search for all mimetypes in the group (‘image/*‘)

Returns:

\OCP\Files\Cache\ICacheEntry[] an array of cache entries where the mimetype matches the search

public OC\Files\Cache\Cache::searchQuery($searchQuery)
Source:lib/private/Files/Cache/Cache.php#840
public OC\Files\Cache\Cache::correctFolderSize($path, $data=null, $isBackgroundScan=false)
Re-calculate the folder size and the size of all parent folders
Source:

lib/private/Files/Cache/Cache.php#892

Parameters:
  • $path (string | bool)
  • $data (array) (optional) meta data of the folder
public OC\Files\Cache\Cache::getIncompleteChildrenCount($fileId)
get the incomplete count that shares parent $folder
Source:

lib/private/Files/Cache/Cache.php#916

Parameters:
  • $fileId (int) the file id of the folder
Returns:

int

public OC\Files\Cache\Cache::calculateFolderSize($path, $entry=null)
calculate the size of a folder and set it in the cache
Source:

lib/private/Files/Cache/Cache.php#940

Parameters:
  • $path (string)
  • $entry (array) (optional) meta data of the folder
Returns:

int

public OC\Files\Cache\Cache::getAll()
get all file ids on the files on the storage
Source:lib/private/Files/Cache/Cache.php#981
Returns:int[]
public OC\Files\Cache\Cache::getIncomplete()
find a folder in the cache which has not been fully scanned
If multiple incomplete folders are in the cache, the one with the highest id will be returned,
use the one with the highest id gives the best result with the background scanner, since that is most
likely the folder where we stopped scanning previously
Source:lib/private/Files/Cache/Cache.php#1005
Returns:string | bool the path of the folder or false when no folder matched
public OC\Files\Cache\Cache::getPathById($id)
get the path of a file on this storage by it’s file id
Source:

lib/private/Files/Cache/Cache.php#1027

Parameters:
  • $id (int) the file id of the file or folder to search
Returns:

string | null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache

public static OC\Files\Cache\Cache::getById($id)
get the storage id of the storage for a file and the internal path of the file
unlike getPathById this does not limit the search to files on this storage and
instead does a global search in the cache table
Source:

lib/private/Files/Cache/Cache.php#1054

Parameters:
  • $id (int)
Returns:

array first element holding the storage id, second the path

Deprecated:

use getPathById() instead

public OC\Files\Cache\Cache::normalize($path)
normalize the given path
Source:

lib/private/Files/Cache/Cache.php#1084

Parameters:
  • $path (string)
Returns:

string

public OC\Files\Cache\Cache::copyFromCache($sourceCache, $sourceEntry, $targetPath)
Copy a file or folder in the cache
Source:

lib/private/Files/Cache/Cache.php#1096

Parameters:
Returns:

int fileid of copied entry