You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, we have some visual elements in an app that we want to fetch once and never have to worry about them being flushed from a cache when it hits a size limit, but at the same time we have other things we might fetch that we are OK with having them dropped from a cache if it hits a limit. If the user of this could somehow specify which cache to use (instead of it always being URLCache.default), that would be helpful.
For example, let's say that some of the main controls in an app, like button images for example, are fetched from a backend, and once they're all fetched, we want to be sure they will stay. In that case, we could pass in a specific URLCache that we know has both enough memory size and storage size to keep everything, even saving it all to storage so that it's available the next time the app runs. Meanwhile, we might have other things that we're fetching from a backend, say for some kind of photo browser, that we want to keep some of them in an in-memory cache to keep the app responsive, but we don't want to cache them to local storage at all, because we know that the next time the app runs, the set of images will be entirely different. So for that, we could prepare a cache that has a large enough in-memory size, but no disk storage at all.
For example:
/* If I had these defined somewhere: */
// A small cache with storage, just large enough for all our GUI controls:
let guiCache = URLCache(memoryCapacity: 2 * 1024 * 1024, diskCapacity: 2 * 1024 * 1024)
// A large in-memory cache for browsing remote photos, none of which will be saved locally:
let photoCache = URLCache(memoryCapacity: 128 * 1024 * 1024, diskCapacity: 0)
/* Then I'd like to be able to pass use them with your class like this: */
NSAsyncCachedImage("https://example.com/plus-icon.png", cache: guiCache) { image in
// This button image will stay around, and probably never need to be fetched again
image
}
NSAsyncCachedImage(pathToSomeRemotePhoto, cache: photoCache) { image in
// This image will display, and be available for some time thanks to the large in-memory cache, but will not be stored
image
}
The text was updated successfully, but these errors were encountered:
Sometimes, we have some visual elements in an app that we want to fetch once and never have to worry about them being flushed from a cache when it hits a size limit, but at the same time we have other things we might fetch that we are OK with having them dropped from a cache if it hits a limit. If the user of this could somehow specify which cache to use (instead of it always being URLCache.default), that would be helpful.
For example, let's say that some of the main controls in an app, like button images for example, are fetched from a backend, and once they're all fetched, we want to be sure they will stay. In that case, we could pass in a specific URLCache that we know has both enough memory size and storage size to keep everything, even saving it all to storage so that it's available the next time the app runs. Meanwhile, we might have other things that we're fetching from a backend, say for some kind of photo browser, that we want to keep some of them in an in-memory cache to keep the app responsive, but we don't want to cache them to local storage at all, because we know that the next time the app runs, the set of images will be entirely different. So for that, we could prepare a cache that has a large enough in-memory size, but no disk storage at all.
For example:
The text was updated successfully, but these errors were encountered: