Documentation

FileCache
in package

Helper functions for managing files cache

Tags
author

zozlak

Table of Contents

Constants

BY_MOD_TIME  = 1
BY_SIZE  = 2
REF_FILE_NAME  = 'ref'

Properties

$dir  : string
$localAccess  : array<string, object>
$log  : LoggerInterface|null

Methods

__construct()  : mixed
clean()  : void
Assures caches doesn't exceed a given size.
getRefFilePath()  : string
Returns the path to the original repository resource.
mintPath()  : string
fetchResourceBinary()  : void
Fetches original resource

Constants

REF_FILE_NAME

public mixed REF_FILE_NAME = 'ref'

Properties

$localAccess

private array<string, object> $localAccess

Methods

__construct()

public __construct(string $cacheDir[, LoggerInterface|null $log = null ][, array<string, object> $localAccess = [] ]) : mixed
Parameters
$cacheDir : string
$log : LoggerInterface|null = null
$localAccess : array<string, object> = []

clean()

Assures caches doesn't exceed a given size.

public clean(float $maxSizeMb, int $mode) : void
Parameters
$maxSizeMb : float

maximum cache size in MB

$mode : int

which files should be removed first

  • ClearCache::BY_MOD_TIME - oldest
  • ClearCache::BY_SIZE - biggest
Tags
throws
BadMethodCallException

getRefFilePath()

Returns the path to the original repository resource.

public getRefFilePath(string $resUrl[, string $expectedMime = '' ][, array<string, mixed> $guzzleOpts = [] ]) : string

Access the resource file directly if possible. If not, downloads it.

Be aware in case of a local access this method doesn't check the access rights.

Parameters
$resUrl : string
$expectedMime : string = ''

expected mime type. If the resource content is downloaded and the download reports different mime type, an error is thrown. Passing an empty value skips the check.

$guzzleOpts : array<string, mixed> = []

guzzle Client options to be used if a resource binary is to be downloaded. Allows passing e.g. credentials.

Return values
string

mintPath()

public mintPath([string $filename = '' ]) : string
Parameters
$filename : string = ''
Return values
string

fetchResourceBinary()

Fetches original resource

private fetchResourceBinary(string $path, string $resUrl, string $expectedMime[, array<string, mixed> $guzzleOpts = [] ]) : void
Parameters
$path : string
$resUrl : string
$expectedMime : string

expected mime type. If the resource content is downloaded and the download reports different mime type, an error is thrown. Passing an empty value skips the check.

$guzzleOpts : array<string, mixed> = []

        
On this page

Search results