To use apcu, the apcu extension has to be installed. You can find it here https://pecl.php.net/package/APCu
Note: apcu is not the same as apc!
APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching. As PHP versions 5.5 and above include their own opcache, APC was no longer compatible, and its opcache functionality became useless. The developers of APC then created APCu, which offers only the object caching (read "in memory data caching") functionality (they removed the outdated opcache).
Wondering how to use apcu? The following example should give you a basic understanding.
<?php
date_default_timezone_set('Europe/Amsterdam');
$apcuAvailabe = function_exists('apcu_enabled') && apcu_enabled();
if($apcuAvailabe)
{
//apcu_clear_cache();
$test1 = apcu_fetch('test1');
$test2 = apcu_fetch('test2');
}
$test1[] = rand(1, 1000);
$test2[] = rand(1, 1000);
if($apcuAvailabe)
{
apcu_store('test1', $test1);
apcu_store('test2', $test2);
}
echo sprintf('current - value = %s<br/>', implode(' ,', $test1));
echo sprintf('current - value = %s<br/>', implode(' ,', $test2));
$aPCUIterator = new APCUIterator();
echo sprintf('totalCount = %s<br/>', $aPCUIterator->getTotalCount());
//echo sprintf('totalHits = %s<br/>', $aPCUIterator->getTotalHits()); // Not implemneted/available?
echo sprintf('totalSize = %s<br/>', $aPCUIterator->getTotalSize());
echo '----------------------------------<br/>';
$aPCUIterator->rewind();
echo sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
$aPCUIterator->next();
echo '----------------------------------<br/>';
echo sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
echo sprintf('valid = %s<br/>', $aPCUIterator->valid() ? 'true' : 'false');
function echoCurrent($current)
{
echo sprintf('current - type = %s<br/>', $current['type']);
echo sprintf('current - key = %s<br/>', $current['key']);
echo sprintf('current - value = %s<br/>', implode(' ,', $current['value']));
//echo sprintf('current - num_hits = %s<br/>', $current['num_hits']); // Not implemneted/available?
echo sprintf('current - mtime = %s<br/>', date("d-m-Y H:i:s", $current['mtime']));
echo sprintf('current - creation_time = %s<br/>', date("d-m-Y H:i:s", $current['creation_time']));
echo sprintf('current - deletion_time = %s<br/>', date("d-m-Y H:i:s", $current['deletion_time']));
echo sprintf('current - access_time = %s<br/>', date("d-m-Y H:i:s", $current['access_time']));
//echo sprintf('current - ref_count = %s<br/>', $current['ref_count']); // Not implemneted/available?
echo sprintf('current - mem_size = %s<br/>', $current['mem_size']);
//echo sprintf('current - ttl = %s<br/>', $current['ttl']); // Not implemneted/available?
}
?>APCu
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
APCu
Референца за `book.apcu.php` со подобрена типографија и навигација.
APC кориснички кеш
Вовед
APCu е мемориска продавница за клуч-вредност за PHP. Клучовите се од тип string а вредностите можат да бидат какви било PHP променливи. APCu поддржува само кеширање на променливи од корисничкиот простор.
APCu кешот е по процес на Windows, така што кога се користи SAPI базиран на процес (наместо на нишка), тој нема да се споделува помеѓу различни процеси.
APCu е APC без кеширање на opcode.
Првата APCu кодна база беше верзија 4.0.0, беше форкната од главата на APC главната гранка во тоа време. Поддршката за PHP 7 е достапна од APCu 5.0.0. Поддршката за PHP 8 е достапна од APCu 5.1.19.
- Installing/Configuring
- Претходно дефинирани константи
- APCu функции
- apcu_add — Кеширај нова променлива во продавницата за податоци
- apcu_cache_info — Презема кеширани информации од продавницата за податоци на APCu
- apcu_cas — Ажурира стара вредност со нова вредност
- apcu_clear_cache — Го чисти APCu кешот
- apcu_dec — Намали складиран број
- apcu_delete — Отстранува складирана променлива од кешот
- apcu_enabled — Дали APCu е употреблив во тековната средина
- apcu_entry — Атомично преземање или генерирање на запис во кешот
- apcu_exists — Проверува дали записот постои
- apcu_fetch — Презема складирана променлива од кешот
- apcu_inc — Зголеми складиран број
- apcu_key_info — Добиј детални информации за клучот во кешот
- apcu_sma_info — Презема информации за распределба на меморијата на APCu
- apcu_store — Кеширај променлива во продавницата за податоци
- APCUIterator — Класата APCUIterator
- APCUIterator::__construct — Конструира APCUIterator итератор објект
- APCUIterator::current — Земи ја тековната ставка
- APCUIterator::getTotalCount — Земи го вкупниот број
- APCUIterator::getTotalHits — Земи го вкупниот број на кеш погодоци
- APCUIterator::getTotalSize — Земи ја вкупната големина на кешот
- APCUIterator::key — Земи го клучот на итераторот
- APCUIterator::next — Помести го покажувачот на следната ставка
- APCUIterator::rewind — Премотува итератор
- APCUIterator::valid — Провери дали тековната позиција е валидна