Opened 5 years ago

Closed 5 years ago

#30984 closed Uncategorized (invalid)

Cache culling.

Reported by: Martin Ennemoser Owned by: nobody
Component: Core (Cache system) Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have an endpoint that needs very long to create a response since the calculation of it takes very long. My approach was to cache the result in a file cache and return the cached result to the user. From time to time I asynchronously recalculate the result and update the cache. Since I don't want to let the cache expire, I set the expire argument to None. The first time, that worked well. But after a couple of hours, I found out that the cache files were deleted randomly. Looking into the code of the FileBasedCache class https://github.com/django/django/blob/master/django/core/cache/backends/filebased.py I noticed that there is a cull() method that randomly deletes my cache files. This is horrible since my users don't get the cached results anymore and have to wait very long until they get the calculated result.
Don't you consider this cull() method dangerous?

Change History (1)

comment:1 by Mariusz Felisiak, 5 years ago

Component: UncategorizedCore (Cache system)
Resolution: invalid
Status: newclosed
Summary: Cache cullingCache culling.

I noticed that there is a cull() method that randomly deletes my cache files. This is horrible since my users don't get the cached results anymore and have to wait very long until they get the calculated result.
Don't you consider this cull() method dangerous?

Cache is to cache values, and all cache system have limited capacity, so to create a space for new values we need to remove old entries, that's why culling is necessary. Cache backends implement their own culling strategy (see documentation). You can increase MAX_ENTRIES, but I think that you're using cache in a wrong way. Nevertheless I don't see here any issue in Django.

Closing per TicketClosingReasons/UseSupportChannels

Note: See TracTickets for help on using tickets.
Back to Top