Contao Utils Bundle

FileCache
in package

Class FileCache.

Will be removed in version 3.0. Use FileStorageUtil instead.

The cache will be created in the cache folder defined by the config (default the huh.utils.filecache.folder parameter) Within the cache folder you can specify a namespace serving as subfolder.

Tags
codeCoverageIgnore

Table of Contents

Properties

$cacheFolder  : string
The folder where the images should be cached.
$cacheFolderWithNamespace  : string
The complete path to the current cache folder including namespace.
$container  : ContainerInterface
$namespace  : string
The subfolder within the cache folder.
$fileUtil  : FileUtil
$projectDir  : string

Methods

__construct()  : mixed
exist()  : bool
Checks if a cached file already exist in cache. Namespace is taken into account.
generateCacheName()  : string
Generate a file name for cache.
get()  : bool|string
Get the file path for the given identifier. Namespace is taken into account.
getAbsoluteCachePath()  : string
Returns the absolute path to the cache folder.
getCacheFileName()  : string
Get the cache file name by the given identifier.
getCacheFilePath()  : string
Same as generateCacheName, but returns complete path to cache.
getCacheFolder()  : string
The cache folder (without namespace).
getCacheFolderWithNamespace()  : string
Get the cache folder (including namespace).
getNamespace()  : string
setCacheFolder()  : mixed
Set cache folder (without namespace).
setNamespace()  : mixed
generatePath()  : mixed
Recreates the path to the current cache folder.

Properties

$cacheFolder

The folder where the images should be cached.

protected string $cacheFolder

$cacheFolderWithNamespace

The complete path to the current cache folder including namespace.

protected string $cacheFolderWithNamespace

$container

protected ContainerInterface $container

$namespace

The subfolder within the cache folder.

protected string $namespace = ''

Methods

__construct()

public __construct(ContainerInterface $container) : mixed
Parameters
$container : ContainerInterface

exist()

Checks if a cached file already exist in cache. Namespace is taken into account.

public exist(string $identifier[, string $fileExtension = '' ]) : bool

Will be removed in 3.0. Use FileStorageUtil instead

Parameters
$identifier : string

The identifier

$fileExtension : string = ''

If not set, a file with no file extension is searched

Tags
throws
Exception
Return values
bool

generateCacheName()

Generate a file name for cache.

public generateCacheName([string $identifier = '' ][, string $prefix = '' ][, bool $more_entropy = true ][, string $fileExtension = '' ]) : string

Will be removed in 3.0. Use FileStorageUtil instead

If a identifier is given, you get the resulting file name. If no identifier is given, if will return a unique file name without extension.

Parameters
$identifier : string = ''

An identifier for the cache. For example be the source file name or path. If empty, a unique filename will be generated.

$prefix : string = ''

Adds a prefix to the generated name. Only if $identifier is empty.

$more_entropy : bool = true

A longer name for the unique filename. Only if $identifier is empty. Default

$fileExtension : string = ''

optional: If set, the file extension will be appended to the generated file name

Return values
string

a unique filename for caching

get()

Get the file path for the given identifier. Namespace is taken into account.

public get(string $identifier[, string $fileExtension = '' ][, callable $saveCallback = null ]) : bool|string

Will be removed in 3.0. Use FileStorageUtil instead

Parameters
$identifier : string
$fileExtension : string = ''
$saveCallback : callable = null

A callback handles the file save functionality. Get filepath, filename and the identifier as parameter. Expects a boolean return value.

Tags
throws
Exception
Return values
bool|string

returns the path of the cached file or false, if cached file could not be found

getAbsoluteCachePath()

Returns the absolute path to the cache folder.

public getAbsoluteCachePath() : string

Will be removed in 3.0. Use FileStorageUtil instead

Return values
string

getCacheFileName()

Get the cache file name by the given identifier.

public getCacheFileName(mixed $identifier) : string

Will be removed in 3.0. Use FileStorageUtil instead

Parameters
$identifier : mixed
Return values
string

getCacheFilePath()

Same as generateCacheName, but returns complete path to cache.

public getCacheFilePath([string $filename = '' ][, string $prefix = '' ][, bool $more_entropy = true ]) : string

Will be removed in 3.0. Use FileStorageUtil instead

If no filename is given, you need to add the file extension by yourself!

Parameters
$filename : string = ''

The filename of the file that should be cached. If empty, a unique filename will be generated.

$prefix : string = ''

Adds a prefix to the generated name. Only if $filename is empty.

$more_entropy : bool = true

A longer name for the unique filename. Only if filename is empty. Default

Return values
string

the path including the filename to save the file to the cache

getCacheFolder()

The cache folder (without namespace).

public getCacheFolder() : string

Will be removed in 3.0. Use FileStorageUtil instead

Return values
string

getCacheFolderWithNamespace()

Get the cache folder (including namespace).

public getCacheFolderWithNamespace() : string

Will be removed in 3.0. Use FileStorageUtil instead

Return values
string

getNamespace()

public getNamespace() : string

Will be removed in 3.0. Use FileStorageUtil instead

Return values
string

setCacheFolder()

Set cache folder (without namespace).

public setCacheFolder(string $cacheFolder) : mixed

Will be removed in 3.0. Use FileStorageUtil instead

Parameters
$cacheFolder : string

setNamespace()

public setNamespace(string $namespace) : mixed

Will be removed in 3.0. Use FileStorageUtil instead

Parameters
$namespace : string

generatePath()

Recreates the path to the current cache folder.

protected generatePath() : mixed

        
On this page

Search results