: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public static function deleteMany($keys, $config = 'default')
$backend = static::pool($config);
foreach ($keys as $key) {
$return[$key] = $backend->delete($key);
* Delete all keys from the cache.
* @param bool $check if true will check expiration, otherwise delete all. This parameter
* will become a no-op value in 4.0 as it is deprecated.
* @param string $config name of the configuration to use. Defaults to 'default'
* @return bool True if the cache was successfully cleared, false otherwise
public static function clear($check = false, $config = 'default')
$engine = static::engine($config);
return $engine->clear($check);
* Delete all keys from the cache from all configurations.
* @param bool $check if true will check expiration, otherwise delete all. This parameter
* will become a no-op value in 4.0 as it is deprecated.
* @return array Status code. For each configuration, it reports the status of the operation
public static function clearAll($check = false)
foreach (self::configured() as $config) {
$status[$config] = self::clear($check, $config);
* Delete all keys from the cache belonging to the same group.
* @param string $group name of the group to be cleared
* @param string $config name of the configuration to use. Defaults to 'default'
* @return bool True if the cache group was successfully cleared, false otherwise
public static function clearGroup($group, $config = 'default')
$engine = static::pool($config);
return $engine->clearGroup($group);
* Retrieve group names to config mapping.
* Cache::config('daily', ['duration' => '1 day', 'groups' => ['posts']]);
* Cache::config('weekly', ['duration' => '1 week', 'groups' => ['posts', 'archive']]);
* $configs = Cache::groupConfigs('posts');
* $configs will equal to `['posts' => ['daily', 'weekly']]`
* Calling this method will load all the configured engines.
* @param string|null $group group name or null to retrieve all group mappings
* @return array map of group and all configuration that has the same group
* @throws \InvalidArgumentException
public static function groupConfigs($group = null)
foreach (array_keys(static::$_config) as $config) {
if (isset(self::$_groups[$group])) {
return [$group => self::$_groups[$group]];
throw new InvalidArgumentException(sprintf('Invalid cache group %s', $group));
* If caching has been disabled with Cache::disable() this method will reverse that effect.
public static function enable()
static::$_enabled = true;
* When disabled all cache operations will return null.
public static function disable()
static::$_enabled = false;
* Check whether or not caching is enabled.
public static function enabled()
return static::$_enabled;
* Provides the ability to easily do read-through caching.
* When called if the $key is not set in $config, the $callable function
* will be invoked. The results will then be stored into the cache config
* Using a Closure to provide data, assume `$this` is a Table object:
* $results = Cache::remember('all_articles', function () {
* return $this->find('all');
* @param string $key The cache key to read/store data at.
* @param callable $callable The callable that provides data in the case when
* the cache key is empty. Can be any callable type supported by your PHP.
* @param string $config The cache configuration to use for this operation.
* @return mixed If the key is found: the cached data, false if the data
* missing/expired, or an error. If the key is not found: boolean of the
public static function remember($key, $callable, $config = 'default')
$existing = self::read($key, $config);
if ($existing !== false) {
$results = call_user_func($callable);
self::write($key, $results, $config);
* Write data for key into a cache engine if it doesn't exist already.
* Writing to the active cache config:
* Cache::add('cached_data', $data);
* Writing to a specific cache config:
* Cache::add('cached_data', $data, 'long_term');
* @param string $key Identifier for the data.
* @param mixed $value Data to be cached - anything except a resource.
* @param string $config Optional string configuration name to write to. Defaults to 'default'.
* @return bool True if the data was successfully cached, false on failure.
* Or if the key existed already.
public static function add($key, $value, $config = 'default')
$pool = static::pool($config);
if (is_resource($value)) {
return $pool->add($key, $value);