Telling IKImageBrowserView not to schedule preload

2019-03-31 17:56发布

For our rewrite of the open-source iMedia framework project (in use currently by dozens of developers), we are switching to IKImageBrowserView, and having a troubling time with caching.

It appears that IKImageBrowserView likes to preload/prefetch a cache of images, as a low-priority background task, as many not-yet-visible items that it can. This might be useful, except that we don't want to load the CPU (and network for remotely-retrieved images) if we can help it.

Especially since we have our own FIFO caching mechanism (so we can share our thumbnail data with other views into the same data), all this is doing is filling up the cache up to capacity and then causing the older items to be dumped.

Is there some way to disable the scheduling of this preloader? (Even if there is an undocumented API that we can gingerly use for now, I'll be sure to open up a request to make it into a public API, since it is really critical to be able to turn this dangerous capability off.)

This will really affect a lot of applications. Any work-arounds you can suggest would be very much appreciated.

BTW Some related discussion: http://lists.apple.com/archives/cocoa-dev/2007/Nov/msg02011.html

1条回答
Root(大扎)
2楼-- · 2019-03-31 18:51

I've been starting to use IKImageBrowserView myself, and I hadn't noticed this before, but indeed I tried it out and am seeing the same behavior with my own app.

It looks like there's a private method on IKImageBrowserView called _shouldProcessLongTasks. I tried overriding it to just return NO, and that appears to prevent the preloading behavior for images that aren't yet visible in the view (at least under Snow Leopard, would have to test under Leopard to see if the behavior is the same). Seems like a fairly low-risk private API usage, since if the method changes, it simply won't be called anymore. When you file a bug with Apple on this, do post the radar number so others affected can file a dupe on it and try to get a public API and/or behavior change for this.

For the record, it looks like the current behavior is that it will prefetch stuff in the background as long as the application is in the foreground and the window containing the view is key. If you switch to another app or window, then it stops preloading.

查看更多
登录 后发表回答