Skip to content

Commit

Permalink
Added reloading of memory cache when reentering the application
Browse files Browse the repository at this point in the history
  • Loading branch information
SteliyanH committed Jun 1, 2018
1 parent b9bcf51 commit 0db8671
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SKCache.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SKCache'
s.version = '1.3.0'
s.version = '1.4.1'
s.summary = 'A caching libary to allow storing each possible type in Swift'

# This description is used to generate tags and improve search results.
Expand Down
17 changes: 15 additions & 2 deletions SKCache/Classes/SKCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public class SKCache: NSCache<AnyObject, AnyObject> {
override init() {
super.init()

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

// MARK: - Override methods
Expand Down Expand Up @@ -297,5 +297,18 @@ public class SKCache: NSCache<AnyObject, AnyObject> {
throw Operations.saveFail
}
}

/// Private method to load the cache
private func loadCache() {
set(object: [SKObject]() as AnyObject)
try? load()
}

/// Private method to handle notifications for active application state
///
/// - Parameter notification: A notification send by the OS
@objc private func applicationIsActivating(notification: Notification) {
loadCache()
}
}

0 comments on commit 0db8671

Please sign in to comment.