Skip to content

Cache timeout much sooner than expected #107

Description

@pai911

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 ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions