Documentation

Cache
in package

Handles caching for NamelessMC.

Tags
author

Christian Metz

version
1.6-Nameless
license

BSD http://www.opensource.org/licenses/bsd-license.php

Table of Contents

Properties

$_cachename  : string
The name of the default cache file.
$_cachepath  : string
The path to the cache file folder.
$_extension  : string
The cache file extension.

Methods

__construct()  : void
Create a new Cache instance.
erase()  : Cache
Erase cached entry by its key.
eraseAll()  : Cache
Erase all cached entries.
eraseExpired()  : int
Erase all expired entries.
getCache()  : string
Cache name Getter.
getCacheDir()  : string
Get the cache directory path.
getCachePath()  : string
Cache path Getter.
getExtension()  : string
Cache file extension Getter.
isCached()  : bool
Check whether data is accociated with a key.
retrieve()  : mixed
Retrieve cached data by its key.
retrieveAll()  : array<string|int, mixed>
Retrieve all cached data.
setCache()  : Cache
Cache name Setter.
setCachePath()  : Cache
Cache path Setter.
setExtension()  : Cache
Cache file extension Setter.
store()  : Cache
Store data in the cache.
_checkCacheDir()  : bool
Check if a writable cache directory exists and if not create a new one.
_checkExpired()  : bool
Check whether a timestamp is still in the duration.
_getHash()  : string
Get the filename hash.
_loadCache()  : mixed
Load appointed cache.

Properties

$_cachename

The name of the default cache file.

private string $_cachename = 'default'

$_cachepath

The path to the cache file folder.

private string $_cachepath = 'cache/'

$_extension

The cache file extension.

private string $_extension = '.cache'

Methods

__construct()

Create a new Cache instance.

public __construct([string|array<string|int, mixed> $config = null ]) : void
Parameters
$config : string|array<string|int, mixed> = null

(optional)

erase()

Erase cached entry by its key.

public erase(string $key) : Cache
Parameters
$key : string

The key to erase

Return values
Cache

eraseAll()

Erase all cached entries.

public eraseAll() : Cache
Return values
Cache

eraseExpired()

Erase all expired entries.

public eraseExpired() : int
Return values
int

Number of entries erased

getCache()

Cache name Getter.

public getCache() : string
Return values
string

Cache name

getCacheDir()

Get the cache directory path.

public getCacheDir() : string
Return values
string

getCachePath()

Cache path Getter.

public getCachePath() : string
Return values
string

The path to the cache file folder

getExtension()

Cache file extension Getter.

public getExtension() : string
Return values
string

Cache file extension

isCached()

Check whether data is accociated with a key.

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

The key to check

Return values
bool

retrieve()

Retrieve cached data by its key.

public retrieve(string $key[, bool $timestamp = false ]) : mixed
Parameters
$key : string

The key to retrieve

$timestamp : bool = false

Whether to check if the cache is expired

Return values
mixed

The cached data or null if not found/expired

retrieveAll()

Retrieve all cached data.

public retrieveAll([bool $meta = false ]) : array<string|int, mixed>
Parameters
$meta : bool = false

(optional)

Return values
array<string|int, mixed>

The cached data

setCache()

Cache name Setter.

public setCache(string $name) : Cache
Parameters
$name : string

Name of cache file to use

Return values
Cache

setCachePath()

Cache path Setter.

public setCachePath(string $path) : Cache
Parameters
$path : string
Return values
Cache

setExtension()

Cache file extension Setter.

public setExtension(string $ext) : Cache
Parameters
$ext : string

Extension to use

Return values
Cache

store()

Store data in the cache.

public store(string $key, mixed $data[, int $expiration = 0 ]) : Cache
Parameters
$key : string

Key to store data under

$data : mixed

Data to store

$expiration : int = 0

Expiration time in seconds

Return values
Cache

_checkCacheDir()

Check if a writable cache directory exists and if not create a new one.

private _checkCacheDir() : bool
Return values
bool

_checkExpired()

Check whether a timestamp is still in the duration.

private _checkExpired(int $timestamp, int $expiration) : bool
Parameters
$timestamp : int

Timestamp to check

$expiration : int

Duration to check

Return values
bool

True if still in duration

_getHash()

Get the filename hash.

private _getHash(string $filename) : string
Parameters
$filename : string
Return values
string

The hashed filename

_loadCache()

Load appointed cache.

private _loadCache() : mixed

        
On this page

Search results