CodeIgniter v4.5 API

FileHandler extends BaseHandler
in package

File system cache handler

Tags
see
FileHandlerTest

Table of Contents

Constants

MAX_KEY_LENGTH  = 255
Maximum key length.
RESERVED_CHARACTERS  = '{}()/\@:'
Reserved characters that cannot be used in a key or tag. May be overridden by the config.

Properties

$mode  : int
Mode for the stored files.
$path  : string
Where to store cached files on the disk.
$prefix  : string
Prefix to apply to cache keys.

Methods

__construct()  : mixed
Note: Use `CacheFactory::getHandler()` to instantiate.
clean()  : bool
Will delete all items in the entire cache.
decrement()  : bool|int
Performs atomic decrementation of a raw stored value.
delete()  : bool
Deletes a specific item from the cache store.
deleteMatching()  : int
Deletes items from the cache store matching a given pattern.
get()  : array<string|int, mixed>|bool|float|int|object|string|null
Attempts to fetch an item from the cache store.
getCacheInfo()  : array<string|int, mixed>|false|object|null
Returns information on the entire cache.
getMetaData()  : array<string|int, mixed>|false|null
Returns detailed information about the specific item in the cache.
increment()  : bool|int
Performs atomic incrementation of a raw stored value.
initialize()  : void
Takes care of any handler-specific setup that must be done.
isSupported()  : bool
Determines if the driver is supported on this system.
remember()  : array<string|int, mixed>|bool|float|int|object|string|null
Get an item from the cache, or execute the given Closure and store the result.
save()  : bool
Saves an item to the cache store.
validateKey()  : string
Validates a cache key according to PSR-6.
deleteFiles()  : bool
Deletes all files contained in the supplied directory path.
getDirFileInfo()  : array<string|int, mixed>|false
Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions
getFileInfo()  : array<string|int, mixed>|false
Given a file and path, returns the name, path, size, date modified Second parameter allows you to explicitly declare what information you want returned Options are: name, server_path, size, date, readable, writable, executable, fileperms Returns FALSE if the file cannot be found.
getItem()  : array{data: mixed, ttl: int, time: int}|false
Does the heavy lifting of actually retrieving the file and verifying it's age.
writeFile()  : bool
Writes a file to disk, or returns false if not successful.

Constants

MAX_KEY_LENGTH

Maximum key length.

public mixed MAX_KEY_LENGTH = 255

RESERVED_CHARACTERS

Reserved characters that cannot be used in a key or tag. May be overridden by the config.

in favor of the Cache config

public mixed RESERVED_CHARACTERS = '{}()/\@:'

From https://github.com/symfony/cache-contracts/blob/c0446463729b89dd4fa62e9aeecc80287323615d/ItemInterface.php#L43

Properties

$path

Where to store cached files on the disk.

protected string $path

$prefix

Prefix to apply to cache keys.

protected string $prefix

May not be used by all handlers.

Methods

__construct()

Note: Use `CacheFactory::getHandler()` to instantiate.

public __construct(Cache $config) : mixed
Parameters
$config : Cache
Tags
throws
CacheException

clean()

Will delete all items in the entire cache.

public clean() : bool
Return values
bool

Success or failure

decrement()

Performs atomic decrementation of a raw stored value.

public decrement(string $key[, int $offset = 1 ]) : bool|int
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
bool|int

delete()

Deletes a specific item from the cache store.

public delete(string $key) : bool
Parameters
$key : string

Cache item name

Return values
bool

Success or failure

deleteMatching()

Deletes items from the cache store matching a given pattern.

public deleteMatching(string $pattern) : int
Parameters
$pattern : string

Cache items glob-style pattern

Return values
int

get()

Attempts to fetch an item from the cache store.

public get(string $key) : array<string|int, mixed>|bool|float|int|object|string|null
Parameters
$key : string

Cache item name

Return values
array<string|int, mixed>|bool|float|int|object|string|null

getCacheInfo()

Returns information on the entire cache.

public getCacheInfo() : array<string|int, mixed>|false|object|null
Return values
array<string|int, mixed>|false|object|null

getMetaData()

Returns detailed information about the specific item in the cache.

public getMetaData(string $key) : array<string|int, mixed>|false|null
Parameters
$key : string

Cache item name.

Return values
array<string|int, mixed>|false|null

Returns null if the item does not exist, otherwise array<string, mixed> with at least the 'expire' key for absolute epoch expiry (or null). Some handlers may return false when an item does not exist, which is deprecated.

increment()

Performs atomic incrementation of a raw stored value.

public increment(string $key[, int $offset = 1 ]) : bool|int
Parameters
$key : string

Cache ID

$offset : int = 1

Step/value to increase by

Return values
bool|int

initialize()

Takes care of any handler-specific setup that must be done.

public initialize() : void

isSupported()

Determines if the driver is supported on this system.

public isSupported() : bool
Return values
bool

remember()

Get an item from the cache, or execute the given Closure and store the result.

public remember(string $key, int $ttl, callable(): mixed $callback) : array<string|int, mixed>|bool|float|int|object|string|null
Parameters
$key : string

Cache item name

$ttl : int

Time to live

$callback : callable(): mixed

Callback return value

Return values
array<string|int, mixed>|bool|float|int|object|string|null

save()

Saves an item to the cache store.

public save(string $key, mixed $value[, int $ttl = 60 ]) : bool
Parameters
$key : string

Cache item name

$value : mixed

The data to save

$ttl : int = 60

Time To Live, in seconds (default 60)

Return values
bool

Success or failure

validateKey()

Validates a cache key according to PSR-6.

public static validateKey(string $key[, string $prefix = '' ]) : string

Keys that exceed MAX_KEY_LENGTH are hashed. From https://github.com/symfony/cache/blob/7b024c6726af21fd4984ac8d1eae2b9f3d90de88/CacheItem.php#L158

Parameters
$key : string

The key to validate

$prefix : string = ''

Optional prefix to include in length calculations

Tags
throws
InvalidArgumentException

When $key is not valid

Return values
string

deleteFiles()

Deletes all files contained in the supplied directory path.

protected deleteFiles(string $path[, bool $delDir = false ][, bool $htdocs = false ][, int $_level = 0 ]) : bool

Files must be writable or owned by the system in order to be deleted. If the second parameter is set to TRUE, any directories contained within the supplied base directory will be nuked as well.

Parameters
$path : string

File path

$delDir : bool = false

Whether to delete any directories found in the path

$htdocs : bool = false

Whether to skip deleting .htaccess and index page files

$_level : int = 0

Current directory depth level (default: 0; internal use only)

Return values
bool

getDirFileInfo()

Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions

protected getDirFileInfo(string $sourceDir[, bool $topLevelOnly = true ][, bool $_recursion = false ]) : array<string|int, mixed>|false

Any sub-folders contained within the specified path are read as well.

Parameters
$sourceDir : string

Path to source

$topLevelOnly : bool = true

Look only at the top level directory specified?

$_recursion : bool = false

Internal variable to determine recursion status - do not use in calls

Return values
array<string|int, mixed>|false

getFileInfo()

Given a file and path, returns the name, path, size, date modified Second parameter allows you to explicitly declare what information you want returned Options are: name, server_path, size, date, readable, writable, executable, fileperms Returns FALSE if the file cannot be found.

protected getFileInfo(string $file[, array<string|int, mixed>|string $returnedValues = ['name', 'server_path', 'size', 'date'] ]) : array<string|int, mixed>|false
Parameters
$file : string

Path to file

$returnedValues : array<string|int, mixed>|string = ['name', 'server_path', 'size', 'date']

Array or comma separated string of information returned

Return values
array<string|int, mixed>|false

getItem()

Does the heavy lifting of actually retrieving the file and verifying it's age.

protected getItem(string $filename) : array{data: mixed, ttl: int, time: int}|false
Parameters
$filename : string
Return values
array{data: mixed, ttl: int, time: int}|false

writeFile()

Writes a file to disk, or returns false if not successful.

protected writeFile(string $path, string $data[, string $mode = 'wb' ]) : bool
Parameters
$path : string
$data : string
$mode : string = 'wb'
Return values
bool

        
On this page

Search results