PHP Class Contao\Cache

The class functions as a global cache container where you can store data that is reused by the application. The cache content is not persisted, so once the process is completed, the data is gone. Usage: public function getResult() { if (!Cache::has('result')) { Cache::set('result') = $this->complexMethod(); } return Cache::get('result'); }
ファイルを表示 Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrData array The cache data
$objInstance Cache Object instance (Singleton)

Public Methods

Method Description
__clone ( ) Prevent cloning of the object (Singleton)
__get ( string $strKey ) : mixed | null Return a cache entry
__isset ( string $strKey ) : boolean Check whether a key is set
__set ( string $strKey, mixed $varValue ) Add a cache entry
__unset ( string $strKey ) Remove a cache entry
get ( string $strKey ) : mixed Return a cache entry
getInstance ( ) : Cache Instantiate the cache object (Factory)
has ( string $strKey ) : boolean Check whether a key is set
remove ( string $strKey ) Remove a cache entry
set ( string $strKey, mixed $varValue ) Add a cache entry

Protected Methods

Method Description
__construct ( ) Prevent direct instantiation (Singleton)

Method Details

__clone() final public method

Prevent cloning of the object (Singleton)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Cache class is now static.
final public __clone ( )

__construct() protected method

Prevent direct instantiation (Singleton)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Cache class is now static.
protected __construct ( )

__get() public method

Return a cache entry
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Cache::get() instead.
public __get ( string $strKey ) : mixed | null
$strKey string The cache key
return mixed | null The cached data

__isset() public method

Check whether a key is set
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Cache::has() instead.
public __isset ( string $strKey ) : boolean
$strKey string The cache key
return boolean True if the key is set

__set() public method

Add a cache entry
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Cache::set() instead.
public __set ( string $strKey, mixed $varValue )
$strKey string The cache key
$varValue mixed The data to be stored

__unset() public method

Remove a cache entry
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Cache::remove() instead.
public __unset ( string $strKey )
$strKey string The cache key

get() public static method

Return a cache entry
public static get ( string $strKey ) : mixed
$strKey string The cache key
return mixed The cached data

getInstance() public static method

Instantiate the cache object (Factory)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Cache class is now static.
public static getInstance ( ) : Cache
return Cache The object instance

has() public static method

Check whether a key is set
public static has ( string $strKey ) : boolean
$strKey string The cache key
return boolean True if the key is set

remove() public static method

Remove a cache entry
public static remove ( string $strKey )
$strKey string The cache key

set() public static method

Add a cache entry
public static set ( string $strKey, mixed $varValue )
$strKey string The cache key
$varValue mixed The data to be cached

Property Details

$arrData protected_oe static_oe property

The cache data
protected static array $arrData
return array

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static Cache,contao $objInstance
return Cache