{"id":22015874,"url":"https://github.com/pircate/moyacache","last_synced_at":"2025-05-07T01:07:04.810Z","repository":{"id":62448043,"uuid":"182917699","full_name":"Pircate/MoyaCache","owner":"Pircate","description":null,"archived":false,"fork":false,"pushed_at":"2019-07-06T05:57:35.000Z","size":299,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T01:06:58.617Z","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":"2019-04-23T03:08:02.000Z","updated_at":"2022-01-03T00:20:26.000Z","dependencies_parsed_at":"2022-11-01T23:17:25.865Z","dependency_job_id":null,"html_url":"https://github.com/Pircate/MoyaCache","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FMoyaCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FMoyaCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FMoyaCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FMoyaCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pircate","download_url":"https://codeload.github.com/Pircate/MoyaCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793644,"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:40.201Z","updated_at":"2025-05-07T01:07:04.788Z","avatar_url":"https://github.com/Pircate.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MoyaCache\n\n[![CI Status](https://img.shields.io/travis/Pircate/MoyaCache.svg?style=flat)](https://travis-ci.org/Pircate/MoyaCache)\n[![Version](https://img.shields.io/cocoapods/v/MoyaCache.svg?style=flat)](https://cocoapods.org/pods/MoyaCache)\n[![License](https://img.shields.io/cocoapods/l/MoyaCache.svg?style=flat)](https://cocoapods.org/pods/MoyaCache)\n[![Platform](https://img.shields.io/cocoapods/p/MoyaCache.svg?style=flat)](https://cocoapods.org/pods/MoyaCache)\n[![codebeat badge](https://codebeat.co/badges/2a844bc6-5a32-4f9c-9585-f34aae5ab6c3)](https://codebeat.co/projects/github-com-pircate-moyacache-master)\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* iOS 9.0\n* Swift 4.2\n\n## Installation\n\nMoyaCache is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'MoyaCache'\n```\n\n## Usage\n\n* 实现缓存协议\n\n```swift\nextension Storable {\n    \n    typealias CachedResponse = Moya.Response\n    \n    public var allowsStorage: (Moya.Response) -\u003e Bool {\n        return { $0.statusCode == 200 }\n    }\n    \n    public func cachedResponse(for key: CachingKey) throws -\u003e Moya.Response {\n        return try Storage\u003cMoya.Response\u003e().object(forKey: key.stringValue)\n    }\n    \n    public func storeCachedResponse(_ cachedResponse: Moya.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` 选择过期时间\n\n```swift\nextension StoryAPI: Cacheable {\n    \n    var expiry: Expiry {\n        return .never\n    }\n}\n```\n\n* 读取缓存\n\n```swift\nlet cachedResponse = try target.cachedResponse()\n```\n\n* 需要缓存的请求调用 `.cache`，普通请求不会缓存\n\n```swift\nprovider.cache.request(target) { result in\n\n}\n```\n\n## Author\n\nPircate, swifter.dev@gmail.com\n\n## License\n\nMoyaCache 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%2Fmoyacache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpircate%2Fmoyacache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Fmoyacache/lists"}