Documentation

FileCache
in package

Local cache for repository resource binary payloads.

Tags
author

zozlak

Table of Contents

Constants

BY_MOD_TIME  = 1
BY_SIZE  = 2
DEFAULT_MAX_DOWNLOAD_SIZE_MB  = 50
MB  = 1048576
REF_FILE_NAME  = 'ref'

Properties

$authConfig  : AuthConfig
$dir  : string
$localAccess  : array<string|int, mixed>
$log  : LoggerInterface|null
$maxDwnldSizeMB  : float
$mimeProperty  : string|NamedNodeInterface

Methods

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

Constants

DEFAULT_MAX_DOWNLOAD_SIZE_MB

public mixed DEFAULT_MAX_DOWNLOAD_SIZE_MB = 50

REF_FILE_NAME

public mixed REF_FILE_NAME = 'ref'

Properties

$localAccess read-only

public array<string|int, mixed> $localAccess = []

$log read-only

public LoggerInterface|null $log = null

$maxDwnldSizeMB read-only

public float $maxDwnldSizeMB = self::DEFAULT_MAX_DOWNLOAD_SIZE_MB

$mimeProperty read-only

public string|NamedNodeInterface $mimeProperty = ''

Methods

__construct()

public __construct(string $dir, AuthConfig $authConfig[, LoggerInterface|null $log = null ][, array<string, object> $localAccess = [] ][, float $maxDwnldSizeMB = self::DEFAULT_MAX_DOWNLOAD_SIZE_MB ][, string $mimeProperty = '' ]) : mixed
Parameters
$dir : string
$authConfig : AuthConfig

authorization config object used to get an authorization-aware guzzle client for fetching remote data

$log : LoggerInterface|null = null
$localAccess : array<string, object> = []
$maxDwnldSizeMB : float = self::DEFAULT_MAX_DOWNLOAD_SIZE_MB

Allows to limit maximum downloaded file size. If the to-be-downloaded file is bigger, the FileCacheException is being thrown. 0 means that files of any size can be downloaded.

$mimeProperty : string = ''

metadata property storing the mime type of a resource - used by the getResourcePath() method

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

fromConfig()

public static fromConfig(mixed $cfg[, LoggerInterface|null $log = null ][, AuthConfig|null $authConfig = null ]) : self
Parameters
$cfg : mixed
$log : LoggerInterface|null = null
$authConfig : AuthConfig|null = null
Return values
self

getRefFilePath()

Returns the path to the original repository resource.

public getRefFilePath(string $resUrl[, string $expectedMime = '' ][, bool $noCache = false ]) : 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.

$noCache : bool = false
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) : 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.


        
On this page

Search results