PHP Class Ouzo\Utilities\Cache

Show file Open project: letsdrink/ouzo Class Usage Examples

Public Methods

Method Description
clear ( ) Clears all items stored in cache.
contains ( $key ) : boolean Checks if cache contains an object for the given key.
get ( $key, null $function = null ) : mixed | null Returns object from cache.
memoize ( $function ) : mixed | null Caches the given closure using filename:line as a key.
put ( $key, $object ) : mixed
size ( ) : integer Returns number of stored objects.

Method Details

clear() public static method

Clears all items stored in cache.
public static clear ( )

contains() public static method

Checks if cache contains an object for the given key.
public static contains ( $key ) : boolean
$key
return boolean

get() public static method

If there's no object for the given key and $functions is passed, $function result will be stored in cache under the given key. Example: $countries = Cache::get("countries", function() {{ expensive computation that returns a list of countries return Country:all(); })
public static get ( $key, null $function = null ) : mixed | null
$key
$function null
return mixed | null

memoize() public static method

Example: $countries = Cache::memoize(function() {{ expensive computation that returns a list of countries return Country:all(); })
public static memoize ( $function ) : mixed | null
$function
return mixed | null

put() public static method

public static put ( $key, $object ) : mixed
$key
$object
return mixed

size() public static method

Returns number of stored objects.
public static size ( ) : integer
return integer