当我在一段时间后(例如几个小时(启动我的应用程序(模拟器或手机(时,Siesta不会加载我的资源,statusOverlay()
将无限期显示。
详细地说,我有一个HomeViewController
,它发出以下请求onViewAppear
:
Api.currentUser.loadIfNeeded()
Api.events.loadIfNeeded()
Api.recommendedProducts.loadIfNeeded()
在我的viewDidLoad
中,我指定了以下各个资源观察器:
statusOverlay.embed(in: self)
Api.currentUser.addObserver(statusOverlay).addObserver(owner: self){
[weak self] resource, _ in
if(resource.isUpToDate){
self?.setWelcomeMessage(user: resource.typedContent())
}
}
Api.events.addObserver(statusOverlay).addObserver(owner: self){
[weak self] resource, _ in
if(resource.isUpToDate){
self?.setEvents(events: resource.typedContent())
}
}
Api.recommendedProducts.addObserver(statusOverlay).addObserver(owner: self){
[weak self] resource, _ in
if(resource.isUpToDate){
self?.setRecommendedProducts(products: resource)
}
}
资源和Siesta实例是在Api类中定义的。虽然这段代码在应用程序的常规使用中效果良好,但当应用程序处于后台或关闭一段时间时,它会遇到困难。
完整的Siesta日志记录结果如下(承载令牌有效,但为了可读性而被截断(:
Siesta:network │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:configuration │ Computing configuration for GET Resource(…/event?dir=desc&order=ends_at)[]
Siesta:configuration │ ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration │ ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration │ ├╴Applying config 6 [/event : Data → Array<Event>]
Siesta:configuration │ ├╴Applying config 20 [**]
Siesta:configuration │ └╴Resulting configuration
Siesta:configuration │ expirationTime: 30.0 sec
Siesta:configuration │ retryTime: 1.0 sec
Siesta:configuration │ progressReportingInterval: 0.05 sec
Siesta:configuration │ headers (1)
Siesta:configuration │ Authorization: Bearer ABCDE
Siesta:configuration │ requestDecorators: 0
Siesta:configuration │ pipeline
Siesta:configuration │ ║ rawData stage (no transformers)
Siesta:configuration │ ║ decoding stage (no transformers)
Siesta:configuration │ ║ parsing stage
Siesta:configuration │ ╟ ⟨text/*⟩ Data → String [transformErrors: true]
Siesta:configuration │ ╟ ⟨image/*⟩ Data → UIImage
Siesta:configuration │ ║ model stage
Siesta:configuration │ ╟ Data → Array<Event>
Siesta:configuration │ ║ cleanup stage (no transformers)
Siesta:network │ Cache request for Resource(…/event?dir=desc&order=ends_at)[]
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:configuration │ Computing configuration for GET Resource(…/my/recommended/products)[]
Siesta:configuration │ ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration │ ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration │ ├╴Applying config 5 [/my/recommended/products : Data → Array<Product>]
Siesta:configuration │ ├╴Applying config 20 [**]
Siesta:configuration │ └╴Resulting configuration
Siesta:configuration │ expirationTime: 30.0 sec
Siesta:configuration │ retryTime: 1.0 sec
Siesta:configuration │ progressReportingInterval: 0.05 sec
Siesta:configuration │ headers (1)
Siesta:configuration │ Authorization: Bearer ABCDE
Siesta:configuration │ requestDecorators: 0
Siesta:configuration │ pipeline
Siesta:configuration │ ║ rawData stage (no transformers)
Siesta:configuration │ ║ decoding stage (no transformers)
Siesta:configuration │ ║ parsing stage
Siesta:configuration │ ╟ ⟨text/*⟩ Data → String [transformErrors: true]
Siesta:configuration │ ╟ ⟨image/*⟩ Data → UIImage
Siesta:configuration │ ║ model stage
Siesta:configuration │ ╟ Data → Array<Product>
Siesta:configuration │ ║ cleanup stage (no transformers)
Siesta:network │ Cache request for Resource(…/my/recommended/products)[]
Siesta:staleness │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:staleness │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:network │ Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])]
Siesta:networkDetails │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[] already started
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:network │ Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])]
Siesta:networkDetails │ Cache request for Resource(…/event?dir=desc&order=ends_at)[] already started
Siesta:staleness │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:network │ Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])]
Siesta:networkDetails │ Cache request for Resource(…/my/recommended/products)[] already started
Siesta:configuration │ Configurations need to be recomputed
Siesta:stateChanges │ Resource(…/event?dir=desc&order=ends_at)[L] wiped
Siesta:network │ Cancelled Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])]
Siesta:network │ Cancelled Cache request for Resource(…/event?dir=desc&order=ends_at)[]
Siesta:observers │ Resource(…/event?dir=desc&order=ends_at)[L] sending newData(wipe) event to 2 observers
Siesta:observers │ ↳ newData(wipe) → <Siesta.ResourceStatusOverlay: 0x7fbe105369a0; frame = (0 0; 320 568); hidden = YES; layer = <CALayer: 0x6080002347c0>>
Siesta:observers │ ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:66)
Siesta:configuration │ Computing configuration for GET Resource(…/event?dir=desc&order=ends_at)[L]
Siesta:configuration │ ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration │ ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration │ ├╴Applying config 6 [/event : Data → Array<Event>]
Siesta:configuration │ ├╴Applying config 20 [**]
Siesta:configuration │ └╴Resulting configuration
Siesta:configuration │ expirationTime: 30.0 sec
Siesta:configuration │ retryTime: 1.0 sec
Siesta:configuration │ progressReportingInterval: 0.05 sec
Siesta:configuration │ headers (1)
Siesta:configuration │ Authorization: Bearer ABCDE
Siesta:configuration │ requestDecorators: 0
Siesta:configuration │ pipeline
Siesta:configuration │ ║ rawData stage (no transformers)
Siesta:configuration │ ║ decoding stage (no transformers)
Siesta:configuration │ ║ parsing stage
Siesta:configuration │ ╟ ⟨text/*⟩ Data → String [transformErrors: true]
Siesta:configuration │ ╟ ⟨image/*⟩ Data → UIImage
Siesta:configuration │ ║ model stage
Siesta:configuration │ ╟ Data → Array<Event>
Siesta:configuration │ ║ cleanup stage (no transformers)
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:network │ Cache request for Resource(…/event?dir=desc&order=ends_at)[L]
Siesta:stateChanges │ Resource(…/user/5b0553d15e70bf00104224fc)[L] wiped
Siesta:network │ Cancelled Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])]
Siesta:network │ Cancelled Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:observers │ Resource(…/user/5b0553d15e70bf00104224fc)[L] sending newData(wipe) event to 1 observer
Siesta:observers │ ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:56)
Siesta:configuration │ Computing configuration for GET Resource(…/user/5b0553d15e70bf00104224fc)[L]
Siesta:configuration │ ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration │ ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration │ ├╴Applying config 2 [/user/* : Data → User]
Siesta:configuration │ ├╴Applying config 20 [**]
Siesta:configuration │ └╴Resulting configuration
Siesta:configuration │ expirationTime: 30.0 sec
Siesta:configuration │ retryTime: 1.0 sec
Siesta:configuration │ progressReportingInterval: 0.05 sec
Siesta:configuration │ headers (1)
Siesta:configuration │ Authorization: Bearer ABCDE
Siesta:configuration │ requestDecorators: 0
Siesta:configuration │ pipeline
Siesta:configuration │ ║ rawData stage (no transformers)
Siesta:configuration │ ║ decoding stage (no transformers)
Siesta:configuration │ ║ parsing stage
Siesta:configuration │ ╟ ⟨text/*⟩ Data → String [transformErrors: true]
Siesta:configuration │ ╟ ⟨image/*⟩ Data → UIImage
Siesta:configuration │ ║ model stage
Siesta:configuration │ ╟ Data → User
Siesta:configuration │ ║ cleanup stage (no transformers)
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:network │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[L]
Siesta:stateChanges │ Resource(…/my/recommended/products)[L] wiped
Siesta:network │ Cancelled Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])]
Siesta:network │ Cancelled Cache request for Resource(…/my/recommended/products)[]
Siesta:observers │ Resource(…/my/recommended/products)[L] sending newData(wipe) event to 2 observers
Siesta:observers │ ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:76)
Siesta:configuration │ Computing configuration for GET Resource(…/my/recommended/products)[L]
Siesta:configuration │ ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration │ ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration │ ├╴Applying config 5 [/my/recommended/products : Data → Array<Product>]
Siesta:configuration │ ├╴Applying config 20 [**]
Siesta:configuration │ └╴Resulting configuration
Siesta:configuration │ expirationTime: 30.0 sec
Siesta:configuration │ retryTime: 1.0 sec
Siesta:configuration │ progressReportingInterval: 0.05 sec
Siesta:configuration │ headers (1)
Siesta:configuration │ Authorization: Bearer ABCDE
Siesta:configuration │ requestDecorators: 0
Siesta:configuration │ pipeline
Siesta:configuration │ ║ rawData stage (no transformers)
Siesta:configuration │ ║ decoding stage (no transformers)
Siesta:configuration │ ║ parsing stage
Siesta:configuration │ ╟ ⟨text/*⟩ Data → String [transformErrors: true]
Siesta:configuration │ ╟ ⟨image/*⟩ Data → UIImage
Siesta:configuration │ ║ model stage
Siesta:configuration │ ╟ Data → Array<Product>
Siesta:configuration │ ║ cleanup stage (no transformers)
Siesta:staleness │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:observers │ ↳ newData(wipe) → <Siesta.ResourceStatusOverlay: 0x7fbe105369a0; frame = (0 0; 320 568); layer = <CALayer: 0x6080002347c0>>
Siesta:network │ Cache request for Resource(…/my/recommended/products)[L]
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:networkDetails │ New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.06342196)
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/event?dir=desc&order=ends_at)[]
Siesta:networkDetails │ New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.07201898)
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/my/recommended/products)[]
Siesta:networkDetails │ New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.08093095)
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness │ Resource(…/user/5b0553d15e70bf00104224fc)[L] loadIfNeeded(): load is already in progress: Request:6000001d6bc0(Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])])
Siesta:staleness │ Resource(…/event?dir=desc&order=ends_at)[L] loadIfNeeded(): load is already in progress: Request:60c0003c2ee0(Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])])
Siesta:staleness │ Resource(…/my/recommended/products)[L] loadIfNeeded(): load is already in progress: Request:60c0003c2fd0(Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])])
实际上,没有发出GET请求,状态Overlay仍然可见。
完全重新启动应用程序是可行的,但这当然不适合最终用户。
你知道我该怎么解决这个问题吗?非常感谢!
日志的这一部分:
Siesta:stateChanges │ Resource(…/user/5b0553d15e70bf00104224fc)[L] wiped
Siesta:network │ Cancelled Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])]
Siesta:network │ Cancelled Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:observers │ Resource(…/user/5b0553d15e70bf00104224fc)[L] sending newData(wipe) event to 1 observer
Siesta:observers │ ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:56)
…表示您正在呼叫Siesta.wipeResources()
或Resource.wipe()
。这将导致取消任何未完成的资源请求。也许您在超时后正在擦除资源?或者什么时候应用程序是前景?
如果您想在擦除资源后立即触发新的加载,那么如果resource.latestData
为零,则让您的观察者调用loadIfNeeded()
。