MCPcopy
hub / github.com/django/django / _cull

Method _cull

django/core/cache/backends/filebased.py:101–116  ·  view source on GitHub ↗

Remove random cache entries if max_entries is reached at a ratio of num_entries / cull_frequency. A value of 0 for CULL_FREQUENCY means that the entire cache will be purged.

(self)

Source from the content-addressed store, hash-verified

99 return False
100
101 def _cull(self):
102 """
103 Remove random cache entries if max_entries is reached at a ratio
104 of num_entries / cull_frequency. A value of 0 for CULL_FREQUENCY means
105 that the entire cache will be purged.
106 """
107 filelist = self._list_cache_files()
108 num_entries = len(filelist)
109 if num_entries < self._max_entries:
110 return # return early if no culling is required
111 if self._cull_frequency == 0:
112 return self.clear() # Clear the cache when CULL_FREQUENCY = 0
113 # Delete a random selection of entries
114 filelist = random.sample(filelist, int(num_entries / self._cull_frequency))
115 for fname in filelist:
116 self._delete(fname)
117
118 def _createdir(self):
119 # Workaround because os.makedirs() doesn't apply the "mode" argument

Callers 1

setMethod · 0.95

Calls 3

_list_cache_filesMethod · 0.95
clearMethod · 0.95
_deleteMethod · 0.95

Tested by

no test coverage detected