{"id":29559794,"url":"https://github.com/hlc0000/swiftlycache","last_synced_at":"2025-07-18T14:05:05.820Z","repository":{"id":45215204,"uuid":"247763103","full_name":"hlc0000/SwiftlyCache","owner":"hlc0000","description":"SwiftlyCache is a thread safe IOS general cache Library","archived":false,"fork":false,"pushed_at":"2021-12-31T03:37:37.000Z","size":135,"stargazers_count":94,"open_issues_count":0,"forks_count":18,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-18T03:54:49.620Z","etag":null,"topics":["cache","cache-storage","disk-cache","ios","memory-cache","swift"],"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/hlc0000.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":"2020-03-16T16:24:37.000Z","updated_at":"2024-11-28T02:18:31.000Z","dependencies_parsed_at":"2022-09-24T19:40:53.151Z","dependency_job_id":null,"html_url":"https://github.com/hlc0000/SwiftlyCache","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/hlc0000/SwiftlyCache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlc0000%2FSwiftlyCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlc0000%2FSwiftlyCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlc0000%2FSwiftlyCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlc0000%2FSwiftlyCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlc0000","download_url":"https://codeload.github.com/hlc0000/SwiftlyCache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlc0000%2FSwiftlyCache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265774603,"owners_count":23826113,"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":["cache","cache-storage","disk-cache","ios","memory-cache","swift"],"created_at":"2025-07-18T14:02:44.369Z","updated_at":"2025-07-18T14:05:05.804Z","avatar_url":"https://github.com/hlc0000.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftlyCache\n\n[![Build Status](https://travis-ci.org/hlc0000/SwiftlyCache.svg?branch=master)](https://travis-ci.org/hlc0000/SwiftlyCache)\n![](https://img.shields.io/cocoapods/p/SwiftlyCache.svg?style=flat)\n![](https://img.shields.io/cocoapods/v/SwiftlyCache.svg?style=flat)\n\n`Swiftlycache` is a thread safe IOS general cache library written with `swift 5`.\n\nFeatures\n===============\n\n- Support all data types complying with the `codable` protocol\n- Objects can be evicted with least-recently-used algorithm\n- It can be configured to automatically recycle objects or manually recycle objects when receiving memory warnings or when the application enters the background\n- Using subscript can make reading and writing data more convenient\n- Support reading data using sequence generator\n\nInstallation\n==============\nCocoaPods\n-------------------------------\n1.Add `pod 'SwiftlyCache'` to your Podfile  \n2.Run `pod install` or `pod update`  \n3.import `SwiftlyCache`\n\nManually\n-------------------------------\n1.Download all the files in the `SwiftlyCache` subdirectory  \n2.Add the source files to your Xcode project  \n\nExample:\n-------------------------------\nCache a struct complying with the  `codable` protocol\n\n```\nstruct Student:Codable {\n     var name:String\n     var age:Int\n     \n     init(name:String,age:Int) {\n         self.name = name\n         self.age = age\n     }\n }\n ```\n ```\n let cache = MultiCache\u003cStudent\u003e()\n \n let shirley = Student(name: \"shirley\", age: 30)\n \n```\n \nSet `key` and `value` to be cached\n \n ```\n cache.set(forKey: \"shirley10\", value: shirley)\n \n``` \n\nQuery the corresponding value according to the given `key`\n\n```\nif let object = cache.object(forKey: \"shirley1\"){\n    print(\"当前Student是:\\(object)\")\n}\n```\n\nQuery whether the corresponding `value` exists in the cache according to `key`\n\n```\n\nlet isExists = cache.isExistsObjectForKey(forKey: \"shirley20\")\n\n```\nSee `swiftlycachedemo` for more test code and cases\n\n\u003cbr/\u003e\u003cbr/\u003e\n---\n\n中文介绍\n============================\n\n `SwiftlyCache`是用 `Swift 5`编写的一个线程安全的iOS通用缓存库。\n\n特性:\n==============\n\n-  支持所有遵守 `Codable`协议的数据类型\n-  支持LRU淘汰算法\n-  当收到内存警告或者App进入后台时,内存缓存可以配置为自动清空或者手动清空\n-  支持使用 `Subscript`，使读写数据更加方便\n-  提供了 `MultiCacheGennerator、` `MemoryCacheGenerator、` `DiskCacheGenerator`用于支持 `for..in、`\n   `compactMap、` `map、` `filter`等方法\n  \n  使用方法:\n  =============\n  CocoaPods:\n  ------------------------------\n  1.在Podfile中添加 `pod 'SwiftlyCache'`     \n  2.执行 `pod install`或者 `pod update`    \n  3.导入  `SwiftlyCache`    \n  \n  手动导入:\n  ------------------------------\n  1.下载 `SwiftlyCache`文件夹内所有内容  \n  2.将 `SwiftlyCache`内的源文件添加到你的工程  \n  \n  示例:\n  ------------------------------\n  将一个遵守`Codable`协议的struct进行缓存\n  \n ```\n struct Student:Codable {\n      var name:String\n      var age:Int\n      \n      init(name:String,age:Int) {\n          self.name = name\n          self.age = age\n      }\n  }\n  ```\n  ```\n  let cache = MultiCache\u003cStudent\u003e()\n  \n  let shirley = Student(name: \"shirley\", age: 30)\n  \n ```\n  \n  设置需要缓存的`Key`和`Value`\n  \n  ```\n  cache.set(forKey: \"shirley10\", value: shirley)\n  \n ``` \n \n 根据给定的`Key`查询对应的Value\n \n ```\n if let object = cache.object(forKey: \"shirley1\"){\n     print(\"当前Student是:\\(object)\")\n }\n ```\n \n 根据`Key`查询缓存中是否存在对应的`Value`\n \n ```\n \n let isExists = cache.isExistsObjectForKey(forKey: \"shirley20\")\n \n ```\n \n更多测试代码和用例见  `SwiftlyCacheDemo`\n\n相关链接:\n==============\n[SwiftlyCache实现](https://juejin.im/post/5e7084886fb9a07c7b784f7f)\n  \n\n  \n  \n  \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlc0000%2Fswiftlycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlc0000%2Fswiftlycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlc0000%2Fswiftlycache/lists"}