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

Cache timeout much sooner than expected #107

Open
pai911 opened this issue Apr 16, 2018 · 2 comments
Open

Cache timeout much sooner than expected #107

pai911 opened this issue Apr 16, 2018 · 2 comments

Comments

@pai911
Copy link

pai911 commented Apr 16, 2018

I set the cache time to 24 hours

     internal struct UserTrackingCache {
        static let cacheName = "userTrackingCache"
        static let locationCacheTime: Double = 24 * 60 * 60 //24 hours
    }
        ///Save to cache
        do {
            let fullKey = "\(root)_\(key)"
            let cache = try Cache<NSData>(name: UserTrackingCache.cacheName)
            let cachedData = NSKeyedArchiver.archivedDataWithRootObject("Y")
            cache.setObject(cachedData, forKey: fullKey, expires: CacheExpiry.Seconds(UserTrackingCache.locationCacheTime))

        } catch _ {
            Log.error("Something went wrong with the cache = \(UserTrackingCache.cacheName)")
        }

I remove the expired cache when App starts in AppDelegate

        do {
            
            let cache = try Cache<NSData>(name: UserTrackingService.UserTrackingCache.cacheName)
            cache.removeExpiredObjects()
            
        } catch _ {
            Log.debug("Something went wrong with the cache")
        }

But I found the cache timeout sooner than I expected. Almost after a few hours, it expires

Does anyone encounter the same issue? or did I do something wrong ?

@pai911
Copy link
Author

pai911 commented Apr 16, 2018

Does AwesomeCache guarantee the cached items not purged before the expiry time

I am thinking that the cache data might be purged by iOS...

@pai911
Copy link
Author

pai911 commented Apr 18, 2018

Answer my own question.

It turns out the default .CachesDirectory can be purged by the OS sometimes.

So I changed the cache dir to .DocumentDirectory, and then everything works fine.

I really think this should be written in the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant