Yac::dump
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Yac::dump
Референца за `yac.dump.php` со подобрена типографија и навигација.
Yac::dump
(PECL yac >= 1.0.0)
Yac::dump — Dump cache entries for inspection
= NULL
Dumps metadata of the entries currently stored in the cache. The values themselves are not returned.
Параметри
limit-
Maximum number of entries to return.
offset-
Number of entries to skip before collecting, which can be used to page through a cache that holds more entries than
limit.
Вратени вредности
Еден array with one element per dumped entry. Each element is itself an array describing the entry:
indexThe slot index of the entry in the hash table.
hashThe 64-bit hash of the key, used for slot probing.
crcThe CRC32 checksum of the stored value, used to detect torn reads.
0for embedded entries, which have no value block.ttlThe expiration timestamp (Unix time).
0means the entry never expires by time. Note that Yac::delete() only marks an entry expired, so deleted entries can still show up in the dump; a non-zerottlin the past indicates an expired or deleted entry.k_lenThe length of the key, in bytes.
v_lenThe length of the value, in bytes. For compressed entries this is the length of the original value before compression (as of yac 2.4.0; earlier versions reported the stored, compressed length).
c_lenOnly present for compressed entries (as of yac 2.4.0): the length of the compressed payload actually stored in shared memory, in bytes. Comparing
c_lenwithv_lenshows how much compression saves per entry.sizeThe allocated size of the value block in shared memory, in bytes.
0for embedded entries.atimeThe last access time (Unix time), updated on each successful Yac::get(). When the cache is full, the entry with the oldest
atimeamong the candidate slots is evicted first (as of yac 2.4.0).hitsA per-entry hit counter, bumped on each successful Yac::get(), reset when the entry is overwritten, deleted or expires (as of yac 2.4.0).
embeddedWhether the value is stored directly inside the slot instead of in a separate value block (as of yac 2.4.0). Small values —
NULL, booleans, small integers, strings of up to 7 bytes and empty arrays — are embedded this way and allocate no value memory at all; for themcrcandsizeare reported as0.keyThe cache key, without any instance prefix.
Примери
Пример #1 Yac::dump() example
<?php
$yac = new Yac();
$yac->set("foo", "bar");
$yac->set("baz", "qux");
print_r($yac->dump());
?>Горниот пример ќе прикаже нешто слично на:
Array
(
[0] => Array
(
[index] => 12345
[hash] => 14463105906481965911
[crc] => 0
[ttl] => 0
[k_len] => 3
[v_len] => 3
[size] => 0
[atime] => 1725955200
[hits] => 0
[embedded] => 1
[key] => foo
)
[1] => Array
(
[index] => 12987
[hash] => 15132029420525657053
[crc] => 0
[ttl] => 0
[k_len] => 3
[v_len] => 3
[size] => 0
[atime] => 1725955200
[hits] => 0
[embedded] => 1
[key] => baz
)
)
Entries are listed in slot order, not in the order they were stored. Embedded entries (short scalars kept inside the slot itself) have
crc and size set to zero; entries stored in a separate value block carry their checksum and block size, and compressed entries additionally carry c_len.
Example #2 Paging through a large cache
limit bounds how many entries a single call returns, and offset skips that many entries before collecting, so the two can be combined to page through a cache that holds more entries than one call may return.
<?php
$yac = new Yac();
$page_size = 100;
$page_num = 2;
// skip the first 100 entries and return the next 100 (page 2)
$page = $yac->dump($page_size, $page_size * ($page_num - 1));
var_dump(count($page));
?>Горниот пример ќе прикаже нешто слично на:
int(100)
Fewer entries than requested are returned when the cache holds fewer entries than the requested page covers, and an empty array is returned once the offset points past the last occupied slot.