{"id":15407035,"url":"https://github.com/bih/swiftcache","last_synced_at":"2025-10-27T21:30:30.639Z","repository":{"id":31183103,"uuid":"34743625","full_name":"bih/SwiftCache","owner":"bih","description":"A wonderfully lightweight cache for Swift","archived":false,"fork":false,"pushed_at":"2016-02-17T17:07:23.000Z","size":308,"stargazers_count":3,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"0.0.1","last_synced_at":"2025-01-21T06:32:38.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/bih.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":"2015-04-28T16:52:02.000Z","updated_at":"2016-07-12T05:59:37.000Z","dependencies_parsed_at":"2022-09-09T03:40:57.222Z","dependency_job_id":null,"html_url":"https://github.com/bih/SwiftCache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bih%2FSwiftCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bih%2FSwiftCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bih%2FSwiftCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bih%2FSwiftCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bih","download_url":"https://codeload.github.com/bih/SwiftCache/tar.gz/refs/heads/0.0.1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238557512,"owners_count":19492014,"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-10-01T16:26:51.318Z","updated_at":"2025-10-27T21:30:30.306Z","avatar_url":"https://github.com/bih.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](SwiftCache.png)\n\nA beautifully lightweight cache written for **Swift**. It has been tested on iOS and OS X. I wrote it over an hour because I couldn't find something good enough and I think you'll like it.\n\nTested with XCode 6.3.1 with Swift 1.2. It requires [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) but that also means it's the only cache I know that works with SwiftyJSON and [Alamofire](https://github.com/alamofire/alamofire) and reliably so!\n\nGive it a spin.\n\n### Installation (Cocoapods)\n\nYou can now have SwiftCache on your Swift project using [Cocoapods](http://cocoapods.org)\n\nAdd this to your `Podfile`\n\n```\nsource 'https://github.com/CocoaPods/Specs.git'\nuse_frameworks!\n\npod 'SwiftCache'\n```\n\n### Installation (Manually)\n\nJust copy the contents of `SwiftCache.swift` and insert it into your XCode. Nothing else necessary.\n\n### Example\n\n```swift\n\n// The above will save it for 60 seconds before expiring the cache\nvar names = SwiftCache(name: \"friendsNames\", expiresIn: 60)\n\n// Want to clear the cache? Run this.\n// names.expireCache()\n\nnames.respond { (data : [String]) in\n  if names.isCached() {\n    println(\"Saved in cache: \\(data)\")\n    println(\"Expires from cache in \\(names.secondsLeftInCache()) seconds\")\n  } else {\n    println(\"Written to cache: \\(data)\")\n  }\n}.request { in\n  // Save to cache (it'll accept any datatype)\n  // In this case, it's a String Array (which is denoted in Swift as [String])\n  names.saveToCache([\"Mike\", \"Jon\", \"Aziz\", \"Tim\", \"Joe\", \"Syeef\", \"Hamer\", \"Li\", \"Gregor\"])\n}\n\n```\n\n### Another Example\n\n```swift\n\n// Let's remember where a user said they're from (setting expiresIn to -1 means forever)\nvar currentUserCity = SwiftCache(name: \"currentUserCity\", expiresIn: -1)\n\n// Want to clear the cache? Run this.\n// currentUserCity.expireCache()\n\nnames.respond { (currentCity : String) in\n  // This will always be ran, but may be from the cache or directly from the block in .request\n  println(\"Hi there stranger from the wonderful city of \\(currentCity)\")\n}.request { in\n  // Here, if the cache is empty or expired, you can show a UIView to ask for their location\n  let aLocationTheUserSelected : String = \"Manchester, United Kingdom\"\n  names.saveToCache(aLocationTheUserSelected)\n}\n\n```\n\nReleased under the [MIT License](http://bih.mit-license.org)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbih%2Fswiftcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbih%2Fswiftcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbih%2Fswiftcache/lists"}