It seems you need to implement your own priority if the last index path passed from prefetchItemsAt indexPaths is not enough.
Requirements 1, 2, 3 and are performed using the priority queue (sorted heap). Requirement 4 depends on your implementation in the priority queue. 5 is pretty wide and vague, just limit the number of calls to your method to retrieve. The priority queue takes on a generic type, so you can use it with an object / class that has properties for the elements you want to extract, below I just use IndexPath.row for simplicity.
Create a priority queue that mediates between your data source and the cache.
then set the data to retrieve from your data source by searching / deleting the priority queue and saving to Kingfisher. Your data source -> PriorityQueue -> Kingfisher -> Cell
func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) { ... for indexPath in IndexPaths {
make sure you initialize the priority queue with the sort function.
you can get a pre-created priority queue from here you will also need a heap to create a priority queue.
more priority queues and heap sorting
Without the appropriate code, it is difficult to offer an effective solution. Hope this helps, cheers and good luck!
source share