Trên GitHub, seatgeek/SGImageCache đã đạt 401 sao, ngôn ngữ Objective-C. A flexible image caching library for image rich iOS applications
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
// Swift
SGImageCache.getImage(url: url) { [weak self] image in
guard let self = self else { return }
self.imageView.image = image
}
This will add the fetch request to fastQueue (a parellel queue). All image fetching (either
from memory, disk, or remote) is performed off the main thread.
This will add the fetch request to slowQueue (a serial queue). All image fetching (either
from memory, disk, or remote) is performed off the main thread.
Adding image fetch tasks to slowQueue is useful for prefetching images for off screen
content. For example if you have data for 100 table rows, but only 3 are on screen at a time,
you would request the images for on screen rows from fastQueue with getImageForURL: and
add the rest to slowQueue with slowGetImageForURL:.
Inform the cache that an urgent image fetch is no longer urgent
// Swift
SGImageCache.moveTaskToSlowQueueForURL(url)
This is useful for deprioritising image fetches for content that has scrolled off screen. The
content may scroll back on screen later, so you still want the fetch to happen, but it is no
longer urgently required.
Perform actions on remote fetch, fail or retry
// Objective-C
SGCachePromise *promise = [SGImageCache getImageForURL:url];
promise.then(^(UIImage *image) {
self.imageView.image = image;
});
promise.onRetry = ^{
// Called when SGImageCache automatically retries
// fetching the image due to a reachability change.
[self showLoadingSpinner];
};
promise.onFail = ^(NSError *error, BOOL fatal) {
// If the failure was fatal, SGImageCache will not
// automatically retry (eg. from a 404)
[self displayError:error];
};
// Swift
let promise = SGImageCache.getImageForURL(url)
promise.swiftThen({object in
if let image = object as? UIImage {
self.imageView.image = image
}
return nil
})
promise.onRetry = {
self.showLoadingSpinner()
}
promise.onFail = { (error: NSError?, wasFatal: Bool) -> () in
self.displayError(error)
}
This is useful for displaying states of network failure, loading spinners on reachability change, or any other functionality that might need to be notified that an image could not be fetched.
fastQueue
fastQueue is a parallel queue, used for urgently required images. The getImageForURL:
method adds tasks to this queue. The maximum number of parallel tasks is managed by iOS, based on the device's number of processors, and other factors.
slowQueue
slowQueue is a serial queue, used for prefetching images that might be required later (eg
for currently off screen content). The slowGetImageForURL: method adds tasks to this queue.
slowQueue is automatically suspended while fastQueue is active, to avoid consuming network bandwidth while urgent image fetches are in progress. Once all fastQueue tasks are completed
slowQueue will be resumed.
Task Deduplication
If an image is requested for a URL that is already queued or in progress, SGImageCache
reuses the existing task, and if necessary will move it from slowQueue to fastQueue,
depending on which image fetch method was used. This ensures that there will be only one
network request per URL, regardless of how many times it's been asked for.
Intelligent image releasing on memory warning
If you use SGImageView instead of UIImageView, and load the image via one of the
setImageForURL: methods, off screen image views will release their image on memory
warning, and subsequently restore them from cache if the image view returns to screen.
This allows off screen but still existing view controllers (eg a previous controller in a
nav controller's stack) to free up memory that would otherwise be unnecessarily retained,
and reduce the chances of your app being terminated by iOS in limited memory situations.
Generic caching of NSData
You can use SGImageCache for caching of generic data in the form of an NSData object (eg. PDFs, JSON payloads). Just use the equivalent SGCache class method instead of the SGImageCache one:
// Objective-C
[SGCache getFileForURL:url].then(^(NSData *data) {
// do something with data
});
// Swift
SGCache.getFileForURL(url).swiftThen({object in
if let data = object as? NSData {
// do something with data
}
return nil
})
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/seatgeek/SGImageCache là nguồn chính thức.
seatgeek/SGImageCache có bao nhiêu sao?
seatgeek/SGImageCache có 401 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/seatgeek/SGImageCache. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
seatgeek/SGImageCache có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho seatgeek/SGImageCache. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
seatgeek/SGImageCache có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho seatgeek/SGImageCache. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
seatgeek/SGImageCache còn đang phát triển không?
Commit gần nhất trên seatgeek/SGImageCache là 6.4 năm trước (theo timestamp GitHub). Repo có 35 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
seatgeek/SGImageCache dùng license gì?
seatgeek/SGImageCache phát hành theo license BSD-2-Clause. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
seatgeek/SGImageCache viết bằng ngôn ngữ gì?
seatgeek/SGImageCache chủ yếu viết bằng Objective-C. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc SGImageCache có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về SGImageCache.