|
| 1 | +--TEST-- |
| 2 | +Test TTL expiration with fragmented memory |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require_once(__DIR__ . '/skipif.inc'); |
| 6 | +if (!function_exists('apcu_inc_request_time')) die('skip APC debug build required'); |
| 7 | +?> |
| 8 | +--INI-- |
| 9 | +apc.enabled=1 |
| 10 | +apc.enable_cli=1 |
| 11 | +apc.use_request_time=1 |
| 12 | +apc.ttl=1 |
| 13 | +apc.shm_size=1M |
| 14 | +--FILE-- |
| 15 | +<?php |
| 16 | + |
| 17 | +apcu_store("long_ttl", 123456789, 100); |
| 18 | +apcu_store("dummy", str_repeat('x', 11000)); |
| 19 | +apcu_inc_request_time(2); |
| 20 | + |
| 21 | +// Fill the cache |
| 22 | +$i = 1; |
| 23 | +while (apcu_exists("dummy")) { |
| 24 | + apcu_store("key_small_" . $i, $i, 3); |
| 25 | + apcu_store("key_large_" . $i, str_repeat('x', 10000), 1); |
| 26 | + |
| 27 | + $i++; |
| 28 | +} |
| 29 | + |
| 30 | +// Expire all large entries |
| 31 | +apcu_inc_request_time(2); |
| 32 | + |
| 33 | +// This insertion should trigger an expunge which expires all large entries |
| 34 | +var_dump(apcu_store("next_large_entry", str_repeat('x', 10000), 1)); |
| 35 | +var_dump(apcu_fetch("next_large_entry") === str_repeat('x', 10000)); |
| 36 | + |
| 37 | +// Check fragmented state (small entries are present, large entries are not present) |
| 38 | +var_dump(apcu_fetch("key_small_1")); |
| 39 | +var_dump(apcu_fetch("key_large_1")); |
| 40 | + |
| 41 | +// Expire all small entries |
| 42 | +apcu_inc_request_time(2); |
| 43 | + |
| 44 | +// This entry should trigger an expunge which expires all small entries. |
| 45 | +// This solves fragmentation which allows this entry to be stored without a full cache wipe. |
| 46 | +var_dump(apcu_store("very_large_entry", str_repeat('x', 20000), 1)); |
| 47 | +var_dump(apcu_fetch("very_large_entry") === str_repeat('x', 20000)); |
| 48 | +var_dump(apcu_fetch("long_ttl")); |
| 49 | + |
| 50 | +?> |
| 51 | +--EXPECT-- |
| 52 | +bool(true) |
| 53 | +bool(true) |
| 54 | +int(1) |
| 55 | +bool(false) |
| 56 | +bool(true) |
| 57 | +bool(true) |
| 58 | +int(123456789) |
0 commit comments