ICache

interface OCP\Files\Cache\ICache
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
Implemented by:OC\Lockdown\Filesystem\NullCache OC\Files\Cache\Cache OC\Files\Cache\FailedCache
Source:lib/public/Files/Cache/ICache.php#40

Methods

public OCP\Files\Cache\ICache::getNumericStorageId()
Get the numeric storage id for this cache’s storage
Source:lib/public/Files/Cache/ICache.php#52
Returns:int
Since:9.0.0
public OCP\Files\Cache\ICache::get($file)
get the stored metadata of a file or folder
Source:lib/public/Files/Cache/ICache.php#61
Parameters:
Returns:\OCP\Files\Cache\ICacheEntry | bool the cache entry or false if the file is not found in the cache
Since:9.0.0
public OCP\Files\Cache\ICache::getFolderContents($folder)
get the metadata of all files stored in $folder
Only returns files one level deep, no recursion
Source:

lib/public/Files/Cache/ICache.php#72

Parameters:
  • $folder (string)
Returns:

\OCP\Files\Cache\ICacheEntry[]

Since:

9.0.0

public OCP\Files\Cache\ICache::getFolderContentsById($fileId)
get the metadata of all files stored in $folder
Only returns files one level deep, no recursion
Source:

lib/public/Files/Cache/ICache.php#83

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

\OCP\Files\Cache\ICacheEntry[]

Since:

9.0.0

public OCP\Files\Cache\ICache::put($file, $data)
store meta data for a file or folder
This will automatically call either insert or update depending on if the file exists
Source:

lib/public/Files/Cache/ICache.php#96

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

int file id

Throws:

\RuntimeException

Since:

9.0.0

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

lib/public/Files/Cache/ICache.php#108

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

int file id

Throws:

\RuntimeException

Since:

9.0.0

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

lib/public/Files/Cache/ICache.php#117

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
Since:

9.0.0

public OCP\Files\Cache\ICache::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/public/Files/Cache/ICache.php#130

Parameters:
  • $file (string)
Returns:

int

Since:

9.0.0

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

lib/public/Files/Cache/ICache.php#139

Parameters:
  • $file (string)
Returns:

int

Since:

9.0.0

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

lib/public/Files/Cache/ICache.php#148

Parameters:
  • $file (string)
Returns:

bool

Since:

9.0.0

public OCP\Files\Cache\ICache::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/public/Files/Cache/ICache.php#158

Parameters:
  • $file (string)
Since:

9.0.0

public OCP\Files\Cache\ICache::move($source, $target)
Move a file or folder in the cache
Source:

lib/public/Files/Cache/ICache.php#167

Parameters:
  • $source (string)
  • $target (string)
Since:

9.0.0

public OCP\Files\Cache\ICache::moveFromCache($sourceCache, $sourcePath, $targetPath)
Move a file or folder in the cache
Note that this should make sure the entries are removed from the source cache
Source:

lib/public/Files/Cache/ICache.php#180

Parameters:
Throws:

\OC\DatabaseException

Since:

9.0.0

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

lib/public/Files/Cache/ICache.php#191

Parameters:
Returns:

int fileid of copied entry

Since:

22.0.0

public OCP\Files\Cache\ICache::getStatus($file)
Get the scan status of a file
- ICache::NOT_FOUND: File is not in the cache
- ICache::PARTIAL: File is not stored in the cache but some incomplete data is known
- ICache::SHALLOW: The folder and it’s direct children are in the cache but not all sub folders are fully scanned
- ICache::COMPLETE: The file or folder, with all it’s children) are fully scanned
Source:

lib/public/Files/Cache/ICache.php#206

Parameters:
  • $file (string)
Returns:

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

Since:

9.0.0

public OCP\Files\Cache\ICache::search($pattern)
search for files matching $pattern, files are matched if their filename matches the search pattern
Source:

lib/public/Files/Cache/ICache.php#216

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

Since:

9.0.0

Deprecated:

9.0.0 due to lack of pagination, not all backends might implement this

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

lib/public/Files/Cache/ICache.php#227

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

Since:

9.0.0

Deprecated:

9.0.0 due to lack of pagination, not all backends might implement this

public OCP\Files\Cache\ICache::searchQuery($query)
Search for files with a flexible query
Source:

lib/public/Files/Cache/ICache.php#237

Parameters:
Returns:

\OCP\Files\Cache\ICacheEntry[]

Throws:

\InvalidArgumentException if the cache is unable to perform the query

Since:

12.0.0

public OCP\Files\Cache\ICache::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/public/Files/Cache/ICache.php#249
Returns:string | bool the path of the folder or false when no folder matched
Since:9.0.0
public OCP\Files\Cache\ICache::getPathById($id)
get the path of a file on this storage by it’s file id
Source:

lib/public/Files/Cache/ICache.php#258

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

Since:

9.0.0

public OCP\Files\Cache\ICache::normalize($path)
normalize the given path for usage in the cache
Source:

lib/public/Files/Cache/ICache.php#267

Parameters:
  • $path (string)
Returns:

string

Since:

9.0.0