Cache

File caching system with per-instance directory path and file prefix

Namespace: Com\Tecnick\File

File: Cache.php line 34

File caching system with per-instance directory path and file prefix

Tags

Methods

__construct()

File: Cache.php line 73

public __construct([string|null $prefix = null ]) : mixed

Parameters

  • $prefix : string|null = null: Common prefix for all cache files; null draws a random one.

Tags

  • throws: Exception when the cache directory cannot be resolved, or no secure randomness is available.

delete()

File: Cache.php line 210

public delete([string|null $type = null ][, string|null $key = null ]) : void

A file name is built as prefix + type + key, so a key can only be matched once a type narrows the name, and a key without a type is rejected.

Parameters

  • $type : string|null = null: Type of files to delete; null means every type.
  • $key : string|null = null: Specific file key to delete; requires $type.

Tags

  • throws: Exception when $key is given without $type.

deleteOlderThan()

File: Cache.php line 285

public deleteOlderThan(int $seconds) : void

Parameters

  • $seconds : int: Maximum age in seconds; files whose mtime is older are removed. Must not be negative.

Tags

getCachePath()

File: Cache.php line 97

public getCachePath() : string

Return values

string

getFilePrefix()

File: Cache.php line 130

public getFilePrefix() : string

Return values

string

getNewFileName()

File: Cache.php line 149

public getNewFileName([string $type = 'tmp' ][, string $key = '0' ]) : string

The returned name carries a random suffix, so it cannot be reconstructed from $type and $key: the caller is responsible for storing it.

Parameters

  • $type : string = ’tmp’: Type of file (used to scope delete())
  • $key : string = ‘0’: File key (used to scope delete())

Tags

  • throws: Exception when a cache file cannot be created, or no secure randomness is available.

Return values

string —

Temporary filename

setCachePath()

File: Cache.php line 113

public setCachePath([string|null $path = null ]) : static

Falls back to K_PATH_CACHE when $path is null, names a stream wrapper, or is not a writable directory. The fallback is silent: compare getCachePath() against the argument to detect it.

Parameters

  • $path : string|null = null: Cache directory path; if null use the K_PATH_CACHE value

Tags

  • throws: Exception when the resulting directory cannot be resolved.

Return values

static