GithubHelp home page GithubHelp logo

缓存机制报错 about rxnetwork HOT 3 OPEN

pircate avatar pircate commented on August 27, 2024
缓存机制报错

from rxnetwork.

Comments (3)

Pircate avatar Pircate commented on August 27, 2024

image

删了APP设置下缓存策略

from rxnetwork.

CoderDoraemon avatar CoderDoraemon commented on August 27, 2024

OnCache+Demo.swift
requestObject 方法指定了 CleanJSONDecoder 缓存正常

import RxSwift
import RxNetwork
import CleanJSON

extension OnCache {
    
    public func requestObject() -> Single<C> {
        return target.request()
            .storeCachedResponse(for: target)
            .map(Network.Response<C>.self, using: CleanJSONDecoder())
            .map {
                if $0.success {
                    return $0.data
                }
                throw Network.Error.status(code: $0.code, message: $0.message)
            }
    }
}

onCache获取缓存需指定解析对应路径

/*
         {
         "code": 2000,
         "message": "Ok",
         "result": []
         }
         */
        BannerAPI.test(count: 10)
            .onCache([BannerModel].self, atKeyPath: "result", using: CleanJSONDecoder(), { (models) in
                debugPrint("onCache:", models.first?.name ?? "")
            })
            .requestObject()
            .subscribe(onSuccess: { (models) in
                debugPrint("onSuccess:", models.first?.name ?? "")
            }, onError: { (error) in
                debugPrint("error:", error)
            })
            .disposed(by: disposeBag)

from rxnetwork.

Pircate avatar Pircate commented on August 27, 2024

这个是正常的,JSON 解析失败导致的,Demo 里面我没有处理这个,多谢反馈。

from rxnetwork.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.