Skip to content

Commit 0db8671

Browse files
committed
Added reloading of memory cache when reentering the application
1 parent b9bcf51 commit 0db8671

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

SKCache.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SKCache'
11-
s.version = '1.3.0'
11+
s.version = '1.4.1'
1212
s.summary = 'A caching libary to allow storing each possible type in Swift'
1313

1414
# This description is used to generate tags and improve search results.

SKCache/Classes/SKCache.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public class SKCache: NSCache<AnyObject, AnyObject> {
194194
override init() {
195195
super.init()
196196

197-
set(object: [SKObject]() as AnyObject)
198-
try? load()
197+
loadCache()
198+
NotificationCenter.default.addObserver(self, selector: #selector(applicationIsActivating(notification:)), name: .UIApplicationWillEnterForeground, object: nil)
199199
}
200200

201201
// MARK: - Override methods
@@ -297,5 +297,18 @@ public class SKCache: NSCache<AnyObject, AnyObject> {
297297
throw Operations.saveFail
298298
}
299299
}
300+
301+
/// Private method to load the cache
302+
private func loadCache() {
303+
set(object: [SKObject]() as AnyObject)
304+
try? load()
305+
}
306+
307+
/// Private method to handle notifications for active application state
308+
///
309+
/// - Parameter notification: A notification send by the OS
310+
@objc private func applicationIsActivating(notification: Notification) {
311+
loadCache()
312+
}
300313
}
301314

0 commit comments

Comments
 (0)