Skip to content

Commit 0415f0a

Browse files
madmajestronikic
authored andcommitted
Try to cleanup cache entries with explicit ttl when apc.ttl is 0
1 parent 635899c commit 0415f0a

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

apc_cache.c

+22-30
Original file line numberDiff line numberDiff line change
@@ -760,40 +760,32 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
760760
/* get available */
761761
available = apc_sma_get_avail_mem(cache->sma);
762762

763-
/* perform expunge processing */
764-
if (!cache->ttl) {
765-
/* check it is necessary to expunge */
766-
if (available < suitable) {
767-
apc_cache_wlocked_real_expunge(cache);
768-
}
769-
} else {
770-
/* check that expunge is necessary */
771-
if (available < suitable) {
772-
size_t i;
773-
774-
/* look for junk */
775-
for (i = 0; i < cache->nslots; i++) {
776-
apc_cache_entry_t **entry = &cache->slots[i];
777-
while (*entry) {
778-
if (apc_cache_entry_expired(cache, *entry, t)) {
779-
apc_cache_wlocked_remove_entry(cache, entry);
780-
continue;
781-
}
782-
783-
/* grab next entry */
784-
entry = &(*entry)->next;
763+
/* check that expunge is necessary */
764+
if (available < suitable) {
765+
size_t i;
766+
767+
/* look for junk */
768+
for (i = 0; i < cache->nslots; i++) {
769+
apc_cache_entry_t **entry = &cache->slots[i];
770+
while (*entry) {
771+
if (apc_cache_entry_expired(cache, *entry, t)) {
772+
apc_cache_wlocked_remove_entry(cache, entry);
773+
continue;
785774
}
786-
}
787775

788-
/* if the cache now has space, then reset last key */
789-
if (apc_sma_get_avail_size(cache->sma, size)) {
790-
/* wipe lastkey */
791-
memset(&cache->header->lastkey, 0, sizeof(apc_cache_slam_key_t));
792-
} else {
793-
/* with not enough space left in cache, we are forced to expunge */
794-
apc_cache_wlocked_real_expunge(cache);
776+
/* grab next entry */
777+
entry = &(*entry)->next;
795778
}
796779
}
780+
781+
/* if the cache now has space, then reset last key */
782+
if (apc_sma_get_avail_size(cache->sma, size)) {
783+
/* wipe lastkey */
784+
memset(&cache->header->lastkey, 0, sizeof(apc_cache_slam_key_t));
785+
} else {
786+
/* with not enough space left in cache, we are forced to expunge */
787+
apc_cache_wlocked_real_expunge(cache);
788+
}
797789
}
798790

799791
apc_cache_wunlock(cache);

0 commit comments

Comments
 (0)