Siesta 加载在陈旧资源上失败
Posted
技术标签:
【中文标题】Siesta 加载在陈旧资源上失败【英文标题】:Siesta loading fails on stale resources 【发布时间】:2018-07-18 12:25:16 【问题描述】:当我在经过一段时间(例如几个小时)后启动我的应用程序(模拟器或手机)时,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 仍然可见。
完全重启应用程序可以解决问题,但这当然不适合最终用户。
您有什么想法可以解决这个问题吗?非常感谢!
【问题讨论】:
【参考方案1】:这部分日志:
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()
。
【讨论】:
谢谢保罗!当我得到一个新的不记名令牌(在这种情况下发生)时,我确实打电话给wipeResources()
。现在我将观察者更改为:Api.events.addObserver(statusOverlay).addObserver(owner: self) [weak self] resource, _ in if(resource.isUpToDate) self?.setEvents(events: resource.typedContent()) else if (resource.latestData == nil) resource.loadIfNeeded()
但是,这并没有奏效。什么有助于将资源请求延迟 0.1 秒(竞争条件?)。以上是关于Siesta 加载在陈旧资源上失败的主要内容,如果未能解决你的问题,请参考以下文章