Skip to content

Commit

Permalink
properly init cache for purge_lru
Browse files Browse the repository at this point in the history
Purging the least recently used cache item relies on a linked
list maintained during cache get and set. While uwsgi is running,
this works well. But if the uwsgi process is stopped, lru_head and
lru_tail are not initialized when loading the existing cache file. As
a consequence, least recently used items never get deleted a full
cache fails to set any new keys until the cache file is deleted.

This patch properly initializes those variables.
  • Loading branch information
niol committed Nov 7, 2023
1 parent 73efb01 commit a488187
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ void uwsgi_cache_fix(struct uwsgi_cache *uc) {
if (uci->expires && (!next_scan || next_scan > uci->expires)) {
next_scan = uci->expires;
}
if (!uc->lru_head && !uci->lru_prev) {
uc->lru_head = i;
}
if (!uc->lru_tail && !uci->lru_next) {
uc->lru_tail = i;
}
restored++;
}
else {
Expand Down

0 comments on commit a488187

Please sign in to comment.