{"id":20382962,"url":"https://github.com/binaryscraping/swift-cache","last_synced_at":"2026-05-30T18:31:16.280Z","repository":{"id":40352580,"uuid":"491864125","full_name":"binaryscraping/swift-cache","owner":"binaryscraping","description":"A type-safe swifty wrapper around NSCache.","archived":false,"fork":false,"pushed_at":"2022-05-13T14:14:15.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-17T09:55:44.761Z","etag":null,"topics":["cache","nscache","swift","type-safe"],"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/binaryscraping.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":"2022-05-13T11:03:23.000Z","updated_at":"2024-09-03T01:19:12.000Z","dependencies_parsed_at":"2022-08-09T18:01:02.895Z","dependency_job_id":null,"html_url":"https://github.com/binaryscraping/swift-cache","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/binaryscraping/swift-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binaryscraping","download_url":"https://codeload.github.com/binaryscraping/swift-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binaryscraping%2Fswift-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33632263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","nscache","swift","type-safe"],"created_at":"2024-11-15T02:19:43.961Z","updated_at":"2026-05-30T18:31:16.259Z","avatar_url":"https://github.com/binaryscraping.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-cache\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbinaryscraping%2Fswift-cache%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/binaryscraping/swift-cache)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbinaryscraping%2Fswift-cache%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/binaryscraping/swift-cache)\n\nA type-safe swifty wrapper around [`NSCache`](https://developer.apple.com/documentation/foundation/nscache).\n\n\n## Getting Started\n\nAdd `swift-cache` as a dependency to your project using SPM.\n\n```swift\n.package(url: \"https://github.com/binaryscraping/swift-cache\", from: \"0.1.0\"),\n```\n\nAnd in your application/target, add `\"Cache\"` to your `\"dependencies\"`.\n\n```swift\n.target(\n  name: \"YourTarget\",\n  dependencies: [\n    .product(name: \"Cache\", package: \"swift-cache\"),\n  ]\n)\n```\n\n## Usage\n\n`Cache` is accessed through a `Cache.Key` type, so start by defining your keys.\n\n```swift\nextension Cache.Key where Value == String {\n  // A key that stores a string value.\n  static let myKey = Cache.Key(\"my_key\")\n}\n\n```\n\nInstantiate a live implementation of the cache type.\n\n```swift\nlet cache = Cache.live()\n```\n\n### Insert\n\n```swift\ncache.set(\"string value\", at: .myKey)\n```\n\nYou can provide an optional lifetime in seconds for the entry.\n\n```swift\ncache.set(\"string value\", at: .myKey, lifetime: 60)\n```\n\n### Retrieve\n\n```swift\nlet value = cache.retrieve(at: .myKey)\n```\n\n### Remove\n```swift\ncache.remove(at: .myKey)\n```\n\n### Usage in tests\n\nThis library provides some helpers for easy usage on tests such as:\n\n#### Noop\n\nAn implementation of `Cache` that does nothing when called.\n\n```swift\nlet cache = Cache.noop\n```\n\n\n#### Failing\n\nAn implementation of `Cache` that fails with an `XCTFail` call.\n\n```swift\nvar setEntryCalled = false\n\nlet cache = Cache.failing\n  .override(\n    setEntry: { entry, key in \n      setEntryCalled = true\n    }\n  )\n  \ncache.set(\"string value\", at: .myKey)\n  \nXCTAssertTrue(setEntryCalled)\n```\n\nAt the code snipped above all calls to a method that wasn't overriden will terminate with a `XCTFail`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinaryscraping%2Fswift-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinaryscraping%2Fswift-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinaryscraping%2Fswift-cache/lists"}