{"id":833,"url":"https://github.com/maquannene/Track","last_synced_at":"2025-07-30T19:32:17.111Z","repository":{"id":56924448,"uuid":"59346941","full_name":"maquannene/Track","owner":"maquannene","description":"Track is a thread safe cache write by Swift. Composed of DiskCache and MemoryCache which support LRU.","archived":false,"fork":false,"pushed_at":"2019-09-03T02:32:30.000Z","size":297,"stargazers_count":270,"open_issues_count":5,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-24T12:46:15.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/maquannene.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":"2016-05-21T07:13:12.000Z","updated_at":"2024-04-03T01:41:53.000Z","dependencies_parsed_at":"2022-08-21T05:20:32.995Z","dependency_job_id":null,"html_url":"https://github.com/maquannene/Track","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maquannene%2FTrack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maquannene%2FTrack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maquannene%2FTrack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maquannene%2FTrack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maquannene","download_url":"https://codeload.github.com/maquannene/Track/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228178890,"owners_count":17881105,"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-01-05T20:15:32.450Z","updated_at":"2024-12-04T19:31:59.434Z","avatar_url":"https://github.com/maquannene.png","language":"Swift","funding_links":[],"categories":["Cache","HarmonyOS"],"sub_categories":["Other free courses","Getting Started","Windows Manager"],"readme":"\u003cp align=\"left\"\u003e\u003cimg src=\"http://ww4.sinaimg.cn/large/65312d9agw1f48moyot15j20du04odg6.jpg\" width=\"300\" height=\"90\"/\u003e\u003c/p\u003e\n\n![Language](https://img.shields.io/badge/language-Swift%203.0-orange.svg)\n[![Pod Version](http://img.shields.io/cocoapods/v/Track.svg?style=flat)](http://cocoadocs.org/docsets/Track/)\n[![Pod Platform](http://img.shields.io/cocoapods/p/Track.svg?style=flat)](http://cocoadocs.org/docsets/Track/)\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/badge/license-MIT-blue.svg)](https://github.com/maquannene/Track/blob/master/LICENSE)\n\nTrack is a thread safe cache write by Swift. Composed of DiskCache and MemoryCache which support LRU.\n\n## Features\n\n* Thread safe: Implement by `dispatch_semaphore_t lock` and `DISPATCH_QUEUE_CONCURRENT`. Cache methods are thread safe and no deadlock.\n\n* LRU: Implement by linkedlist, it`s fast. You can manage a cache through functions to limit size, age of entries and memory usage to eliminate least recently used object.\n\n* Support async and sync operation.\n\n* Cache implement `SequenceType` `Generator`, support `subscrip` `for ... in` `map` `flapmap` `filter`...\n\n## Use\n\n**Base use**\n\nSupport Sync and Async Set, Get, RemoveObject, RemoveAll and Subscript.\n\n```swift\nlet track = Cache.shareInstance\n\ntrack.set(object: \"object\", forKey: \"key\")\n\ntrack.object(forKey: \"key\")\n\ntrack.removeObject(forKey: \"key\") { (cache, key, object) in }\n\ntrack.removeAllObjects { (cache, key, object) in }\n\ntrack[\"key\"] = \"object\"\n\nprint(track[\"key\"])\n```\n\n**Other use**\n\nMemoryCache and DiskCache has feature of LRU, so they can eliminate least recently used object according `countLimit`, `costLimit` and `ageLimit`.\n\n```swift\nlet diskcache = DiskCache.shareInstance\n\ndiskcache.countLimit = 20\n\ndiskcache.costLimit = 1024 * 10\n\nlet memorycache = MemoryCache.shareInstance\n\nmemorycache.trim(toAge: 1000) { (cache, key, object) in }\n\nmemorycache.trim(toCount: 10) { (cache, key, object) in }\n```\n\n**New features: SequenceType Generator**\n\nCache support thread safe `for ... in` `map` `forEache`...\n\n```swift\nlet cache: Cache = Cache.shareInstance\n\nfor i in 1 ... 5 {\n    cache.set(object: \"\\(i)\", forKey: \"\\(i)\")\n}\n\nfor object in cache {\n    print(object)\n}\n```\n\n```\noutput: (\"5\", 5) (\"4\", 4) (\"3\", 3) (\"2\", 2) (\"1\", 1)\n```\n\n```\ncache.forEach {\n    print($0)\n}\n```\n\n```\noutput: (\"1\", 1) (\"2\", 2) (\"3\", 3) (\"4\", 4) (\"5\", 5)\n```\n\n```\nlet values = cache.map { return $0 }\n\nprint(values)\n```\n\n```\noutput: [(\"5\", 5), (\"4\", 4), (\"3\", 3), (\"2\", 2), (\"1\", 1)]\n```\n\n## Installation\n\n**CocoaPods**\n\nSupport Swift 5.0\n\n```\npod 'Track', :git =\u003e 'https://github.com/maquannene/Track.git', :branch =\u003e 'master'\n```\n\n**Manually**\n\n1. Download and drop ```/Track``` folder in your project.  \n2. Congratulations! \n\n## Thanks\n\nThanks YYCache，PINCache very much. Some ideas from them.\n\n## License\n\nTrack is released under the MIT license.\n\n如果来自天朝[点击查看](https://github.com/maquannene/Track/blob/master/%E5%A6%82%E6%9E%9C%E4%BD%A0%E5%9C%A8%E5%A4%A9%E6%9C%9D.md)更多实现细节文章\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaquannene%2FTrack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaquannene%2FTrack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaquannene%2FTrack/lists"}