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)
| 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 |
no test coverage detected