1

当我在经过一段时间(例如几个小时)后启动我的应用程序(模拟器或手机)时,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 请求,并且 statusOverlay 仍然可见。

完全重启应用程序可以解决问题,但这当然不适合最终用户。

你有什么想法我可以解决这个问题吗?提前谢谢了!

4

1 回答 1

0

日志的这一部分:

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()。这会导致取消任何未完成的资源请求。也许您在超时后擦除资源?或者当应用程序处于前台时?

如果你想在擦除资源立即触发一个新的负载,那么让你的观察者调用loadIfNeeded()ifresource.latestData为 nil。

于 2018-07-18T19:49:15.327 回答