Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clearCache, cleanExpiredCache function #1494

Merged
merged 2 commits into from
Aug 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Sources/Cache/ImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ open class ImageCache {
}

// MARK: Cleaning
/// Clears the memory & disk storage of this cache. This is an async operation.
///
/// - Parameter handler: A closure which is invoked when the cache clearing operation finishes.
/// This `handler` will be called from the main queue.
public func clearCache(completion handler: (() -> Void)? = nil) {
clearMemoryCache()
clearDiskCache(completion: handler)
}

/// Clears the memory storage of this cache.
@objc public func clearMemoryCache() {
try? memoryStorage.removeAll()
Expand All @@ -597,7 +606,7 @@ open class ImageCache {
///
/// - Parameter handler: A closure which is invoked when the cache clearing operation finishes.
/// This `handler` will be called from the main queue.
open func clearDiskCache(completion handler: (()->())? = nil) {
open func clearDiskCache(completion handler: (() -> Void)? = nil) {
ioQueue.async {
do {
try self.diskStorage.removeAll()
Expand All @@ -607,8 +616,14 @@ open class ImageCache {
}
}
}

/// Clears the expired images from memory & disk storage. This is an async operation.
open func cleanExpiredCache(completion handler: (() -> Void)? = nil) {
cleanExpiredMemoryCache()
cleanExpiredDiskCache(completion: handler)
}

/// Clears the expired images from disk storage. This is an async operation.
/// Clears the expired images from disk storage.
open func cleanExpiredMemoryCache() {
memoryStorage.removeExpired()
}
Expand Down