{"id":22015884,"url":"https://github.com/pircate/rxmoyacache","last_synced_at":"2025-10-28T08:34:03.297Z","repository":{"id":56921791,"uuid":"148170625","full_name":"Pircate/RxMoyaCache","owner":"Pircate","description":null,"archived":false,"fork":false,"pushed_at":"2019-03-06T06:54:32.000Z","size":452,"stargazers_count":13,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T01:06:31.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pircate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-10T14:44:36.000Z","updated_at":"2024-04-16T10:11:24.000Z","dependencies_parsed_at":"2022-08-21T04:50:08.268Z","dependency_job_id":null,"html_url":"https://github.com/Pircate/RxMoyaCache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxMoyaCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxMoyaCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxMoyaCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxMoyaCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pircate","download_url":"https://codeload.github.com/Pircate/RxMoyaCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793643,"owners_count":21805057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T04:29:44.836Z","updated_at":"2025-10-28T08:33:58.259Z","avatar_url":"https://github.com/Pircate.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RxMoyaCache\n\n[![CI Status](https://img.shields.io/travis/Pircate/RxMoyaCache.svg?style=flat)](https://travis-ci.org/Pircate/RxMoyaCache)\n[![Version](https://img.shields.io/cocoapods/v/RxMoyaCache.svg?style=flat)](https://cocoapods.org/pods/RxMoyaCache)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/RxMoyaCache.svg?style=flat)](https://cocoapods.org/pods/RxMoyaCache)\n[![Platform](https://img.shields.io/cocoapods/p/RxMoyaCache.svg?style=flat)](https://cocoapods.org/pods/RxMoyaCache)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n## Installation\n\nRxMoyaCache is available through [CocoaPods](https://cocoapods.org) or [Carthage](https://github.com/Carthage/Carthage). To install\nit, simply add the following line to your Podfile or Cartfile:\n\n### CocoaPods\n```ruby\npod 'RxMoyaCache'\n```\n\n### Carthage\n```ruby\ngithub \"Pircate/RxMoyaCache\"\n```\n\n## Usage\n\n### Import\n```swift\nimport RxMoyaCache\n```\n\n### Snippet\n\n给 `Storable` 添加默认实现，具体实现请看 Demo\n```swift\nextension Storable where Self: TargetType {\n    \n    public var allowsStorage: (Response) -\u003e Bool {\n        return MoyaCache.shared.storagePolicyClosure\n    }\n    \n    public func cachedResponse(for key: CachingKey) throws -\u003e Response {\n        return try Storage\u003cMoya.Response\u003e().object(forKey: key.stringValue)\n    }\n    \n    public func storeCachedResponse(_ cachedResponse: Response, for key: CachingKey) throws {\n        try Storage\u003cMoya.Response\u003e().setObject(cachedResponse, forKey: key.stringValue)\n    }\n    \n    public func removeCachedResponse(for key: CachingKey) throws {\n        try Storage\u003cMoya.Response\u003e().removeObject(forKey: key.stringValue)\n    }\n    \n    public func removeAllCachedResponses() throws {\n        try Storage\u003cMoya.Response\u003e().removeAll()\n    }\n}\n```\n\n`target` 遵循 `Cacheable` 协议\n```swift\nenum StoryAPI: TargetType, Cacheable {\n    case latest\n}\n```\n\n读取缓存\n```swift\nlet provider = MoyaProvider\u003cStoryAPI\u003e()\nprovider.rx.cache\n    .request(.latest)\n    .map(StoryListModel.self)\n    .subscribe(onNext: { object in\n        debugPrint(\"onNext:\", object.topStories[0].title)\n    }).disposed(by: disposeBag)\n\n// or\n\nprovider.rx.onCache(.latest, type: StoryListModel.self) { object in\n        debugPrint(\"onCache\", object.topStories[0].title)\n    }.request()\n    .subscribe(onSuccess: { object in\n        debugPrint(\"onSuccess\", object.topStories[0].title)\n    }).disposed(by: disposeBag)\n```\n\n## Author\n\nPircate, gao497868860@163.com\n\n## License\n\nRxMoyaCache is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Frxmoyacache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpircate%2Frxmoyacache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Frxmoyacache/lists"}