OpenCart 🇺🇦

Схема

public mixed get ( string $key )

Аргументы

Аргумент Возможный тип Описание
$key string

Описание

Функция, которая позволяет получить из кеша запись по ключу $key

Пример использования:

// пример в моделе catalog/model/catalog/product.php
$product_data = $this->cache->get('product.latest.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $customer_group_id . '.' . (int)$limit);

Исходный код

$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');

if ($files) {
	$cache = file_get_contents($files[0]);

	$data = unserialize($cache);

	foreach ($files as $file) {
		$time = substr(strrchr($file, '.'), 1);

		if ($time < time()) {
			if (file_exists($file)) {
				unlink($file);
			}
		}
	}

	return $data;
}