\OCP\Files\CacheICache

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

Summary

Methods
Constants
getNumericStorageId()
get()
getFolderContents()
getFolderContentsById()
put()
insert()
update()
getId()
getParentId()
inCache()
remove()
move()
moveFromCache()
getStatus()
search()
searchByMime()
searchByTag()
getIncomplete()
getPathById()
normalize()
NOT_FOUND
PARTIAL
SHALLOW
COMPLETE
No protected methods found
N/A
No private methods found
N/A

Constants

NOT_FOUND

NOT_FOUND

PARTIAL

PARTIAL

SHALLOW

SHALLOW

COMPLETE

COMPLETE

Methods

getNumericStorageId()

getNumericStorageId() : integer

Get the numeric storage id for this cache's storage

Returns

integer

get()

get(  $file) : \OCP\Files\Cache\ICacheEntry|false

get the stored metadata of a file or folder

Parameters

$file

Returns

\OCP\Files\Cache\ICacheEntry|false —

the cache entry or false if the file is not found in the cache

getFolderContents()

getFolderContents(string  $folder) : array<mixed,\OCP\Files\Cache\ICacheEntry>

get the metadata of all files stored in $folder

Only returns files one level deep, no recursion

Parameters

string $folder

Returns

array<mixed,\OCP\Files\Cache\ICacheEntry>

getFolderContentsById()

getFolderContentsById(integer  $fileId) : array<mixed,\OCP\Files\Cache\ICacheEntry>

get the metadata of all files stored in $folder

Only returns files one level deep, no recursion

Parameters

integer $fileId

the file id of the folder

Returns

array<mixed,\OCP\Files\Cache\ICacheEntry>

put()

put(string  $file, array  $data) : integer

store meta data for a file or folder This will automatically call either insert or update depending on if the file exists

Parameters

string $file
array $data

Throws

\RuntimeException

Returns

integer —

file id

insert()

insert(string  $file, array  $data) : integer

insert meta data for a new file or folder

Parameters

string $file
array $data

Throws

\RuntimeException

Returns

integer —

file id

update()

update(integer  $id, array  $data) 

update the metadata of an existing file or folder in the cache

Parameters

integer $id

the fileid of the existing file or folder

array $data

[$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged

getId()

getId(string  $file) : integer

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

Parameters

string $file

Returns

integer

getParentId()

getParentId(string  $file) : integer

get the id of the parent folder of a file

Parameters

string $file

Returns

integer

inCache()

inCache(string  $file) : boolean

check if a file is available in the cache

Parameters

string $file

Returns

boolean

remove()

remove(string  $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

Parameters

string $file

move()

move(string  $source, string  $target) 

Move a file or folder in the cache

Parameters

string $source
string $target

moveFromCache()

moveFromCache(\OCP\Files\Cache\ICache  $sourceCache, string  $sourcePath, string  $targetPath) 

Move a file or folder in the cache

Note that this should make sure the entries are removed from the source cache

Parameters

\OCP\Files\Cache\ICache $sourceCache
string $sourcePath
string $targetPath

Throws

\OC\DatabaseException

getStatus()

getStatus(string  $file) : integer

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

Parameters

string $file

Returns

integer —

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

search()

search(string  $pattern) : array<mixed,\OCP\Files\Cache\ICacheEntry>

search for files matching $pattern, files are matched if their filename matches the search pattern

Parameters

string $pattern

the search pattern using SQL search syntax (e.g. '%searchstring%')

Returns

array<mixed,\OCP\Files\Cache\ICacheEntry> —

an array of cache entries where the name matches the search pattern

searchByMime()

searchByMime(string  $mimetype) : array<mixed,\OCP\Files\Cache\ICacheEntry>

search for files by mimetype

Parameters

string $mimetype

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

array<mixed,\OCP\Files\Cache\ICacheEntry> —

an array of cache entries where the mimetype matches the search

searchByTag()

searchByTag(string|integer  $tag, string  $userId) : array<mixed,\OCP\Files\Cache\ICacheEntry>

Search for files by tag of a given users.

Note that every user can tag files differently.

Parameters

string|integer $tag

name or tag id

string $userId

owner of the tags

Returns

array<mixed,\OCP\Files\Cache\ICacheEntry> —

file data

getIncomplete()

getIncomplete() : string|boolean

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

Returns

string|boolean —

the path of the folder or false when no folder matched

getPathById()

getPathById(integer  $id) : string|null

get the path of a file on this storage by it's file id

Parameters

integer $id

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

normalize()

normalize(string  $path) : string

normalize the given path for usage in the cache

Parameters

string $path

Returns

string