Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change behavior of smart configuration setting #537

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions apc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,9 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
/* gc */
apc_cache_wlocked_gc(cache);

/* check that expunge is necessary */
if (cache->smart > 0L && apc_sma_get_avail_mem(cache->sma) >= (size_t) (cache->smart * size)) {
apc_cache_wunlock(cache);
return;
}
/* smart > 1 increases the probability of a full cache wipe,
* so expunge() is called less often when memory is low. */
size = (cache->smart > 0L) ? (size_t) (cache->smart * size) : size;

/* look for junk */
for (i = 0; i < cache->nslots; i++) {
Expand Down
16 changes: 4 additions & 12 deletions apc_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,12 @@ PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name);

/* {{{ apc_cache_default_expunge
* Where smart is not set:
* Where no ttl is set on cache:
* 1) Perform cleanup of stale entries
* 2) Expunge if available memory is less than sma->size/2
* Where ttl is set on cache:
* 1) Perform cleanup of stale entries
* 2) If available memory if less than the size requested, run full expunge
* 1) Perform cleanup of stale entries
* 2) If available memory is less than the size requested, run full expunge
*
* Where smart is set:
* Where no ttl is set on cache:
* 1) Perform cleanup of stale entries
* 2) Expunge is available memory is less than size * smart
* Where ttl is set on cache:
* 1) Perform cleanup of stale entries
* 2) If available memory if less than the size requested, run full expunge
* 1) Perform cleanup of stale entries
* 2) If available memory is less than the size requested * smart, run full expunge
*
* The TTL of an entry takes precedence over the TTL of a cache
*/
Expand Down