Класс Phalcon\Cache\Frontend\Msgpack
расширяет класс Phalcon\Cache\Frontend\Data
реализует Phalcon\Cache\FrontendInterface
Позволяет кешировать данные PHP в сериализованной форме с использованием расширения msgpack. Этот адаптер использует фронтенд Msgpack для хранения кэшированного контента и требует расширение msgpack.
use Phalcon\Cache\Backend\File;
use Phalcon\Cache\Frontend\Msgpack;
// Cache the files for 2 days using Msgpack frontend
$frontCache = new Msgpack(
[
"lifetime" => 172800,
]
);
// Create the component that will cache "Msgpack" to a "File" backend
// Set the cache file directory - important to keep the "/" at the end of
// of the value for the folder
$cache = new File(
$frontCache,
[
"cacheDir" => "../app/cache/",
]
);
$cacheKey = "robots_order_id.cache";
// Try to get cached records
$robots = $cache->get($cacheKey);
if ($robots === null) {
// $robots is null due to cache expiration or data do not exist
// Make the database call and populate the variable
$robots = Robots::find(
[
"order" => "id",
]
);
// Store it in the cache
$cache->save($cacheKey, $robots);
}
// Use $robots
foreach ($robots as $robot) {
echo $robot->name, "\n";
}
Методы
public __construct ([array $frontendOptions])
Конструктор Phalcon\Cache\Frontend\Msgpack
public getLifetime ()
Возвращает срок хранения кэша
public isBuffering ()
Проверяет, буферизует ли фронтенд вывод
public start ()
Инициализирует буферизацию вывода фронтенда. Фактически, ничего не делает
public getContent ()
Возвращает кэшированный вывод
public stop ()
Останавливает буферизацию вывода фронтенда
public beforeStore (mixed $data)
Сериализует данные перед их сохранением
public afterRetrieve (mixed $data)
Десериализует данные после извлечения
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Cache_Frontend_Msgpack.html