ios - How to prevent using cache when new data is available? -


i'm caching data in coredata within app reduce updating request when there's nothing new.

here's caching logic in pseudo code:

if cacheexistsincoredata {   if cacheisoutdated  {     loaddatafromremoteandcacheitwithcurrentdate()     }else {     usecache() }else {   loaddatafromremoteandcacheitwithcurrentdate() } 

how check if cache outdated:

func checkifcacheisoutdated {   if lastcacheddate isorderthan selfdefinedcheckingdate {    return true // need load new data   }else {    return false // use cache   } } 

this mechanism works fine time.

while in rare situation find program caches wrong data right date, means user might see older data , not update when new 1 available.

if there's nothing wrong caching logic, wonder if reason when remote data fetched app before gets updated , gets stored in core data latest date time.

a cache in core data includes:

data(provided remote server) //nothing can it...

date(provided me using nsdate())

how can make sure if 2 objects correctly connected (latest data current time) before storing them?

assuming calling web api, of web apis return cache headers. safe cache data based on cache header value, way there wont stale cache.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -