{"id":822,"url":"https://github.com/nrkno/yr-cachyr","last_synced_at":"2025-06-23T14:07:51.421Z","repository":{"id":56905543,"uuid":"76033823","full_name":"nrkno/yr-cachyr","owner":"nrkno","description":"A small key-value data cache for iOS, macOS and tvOS, written in Swift.","archived":false,"fork":false,"pushed_at":"2020-12-01T11:35:08.000Z","size":89,"stargazers_count":126,"open_issues_count":1,"forks_count":7,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-24T00:04:26.631Z","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/nrkno.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-12-09T12:31:34.000Z","updated_at":"2024-05-29T10:01:56.000Z","dependencies_parsed_at":"2022-08-20T19:20:26.151Z","dependency_job_id":null,"html_url":"https://github.com/nrkno/yr-cachyr","commit_stats":null,"previous_names":["yr/cachyr"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/nrkno/yr-cachyr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkno%2Fyr-cachyr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkno%2Fyr-cachyr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkno%2Fyr-cachyr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkno%2Fyr-cachyr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrkno","download_url":"https://codeload.github.com/nrkno/yr-cachyr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrkno%2Fyr-cachyr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261491821,"owners_count":23166678,"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.174Z","updated_at":"2025-06-23T14:07:51.403Z","avatar_url":"https://github.com/nrkno.png","language":"Swift","funding_links":[],"categories":["Cache","Libs","Cache [🔝](#readme)","Data and Storage"],"sub_categories":["Cache","Getting Started"],"readme":"# Cachyr\n\nA typesafe key-value data cache for iOS, macOS, tvOS and watchOS written in Swift.\n\nThere already exists plenty of cache solutions, so why create one more? We had a few requirements where existing solutions fulfilled some of them but not all:\n\n- Written purely in Swift 3.\n- Type safety while still allowing any kind of data to be stored.\n- Disk and memory caching.\n- Easy way to populate cache when a lookup results in a cache miss.\n- Clean, single-purpose implementation. Do caching and nothing else.\n\n\n## Installation\n\n### CocoaPods\n\n```\nAdd to Podfile:\npod 'Cachyr'\n\nThen:\n$ pod install\n```\n\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.\n\nTo integrate `Cachyr` into your Xcode project using Xcode 11, specify it in `File \u003e Swift Packages \u003e Add`:\n\n```\nhttps://github.com/nrkno/yr-cachyr\n```\n\n### Manual\n\nClone the repo somewhere suitable, like inside your project repo so Cachyr can be added as a subrepo, then drag `Cachyr.xcodeproj` into your project.\n\nAlternatively build the framework and add it to your project.\n\n\n## Usage\n\n```swift\nlet cache = DataCache()\nlet key = \"foo\"\nlet text = \"bar\"\ncache.setValue(text, for: key)\n\n// ... do important things ...\n\nlet cachedText: String? = cache.value(for: key)\n\n// Or asynchronously\nlet cachedText = cache.value(for: key) { (value: String?) in\n    // Do something with value\n}\n```\n\nIn this example the string `bar` is stored in the cache for the key `foo`. It is later retrieved as a string optional by explicitly declaring `String?` as the value type. Let's look at how generics enable easy data transformation.\n\n```swift\nlet textAsData = cache.value(for: key) { (value: Data?) in\n    print(value)\n}\n```\n\nNow the exact same key is used to retrieve the data representation of the value. The cache stores everything as data, and by implementing the `DataConvertable` protocol for a type it is possible to convert the cached data to the return type you define when retrieving a value.\n\nThere are default `DataConvertable` implementations for `Data`, `String`, `Int` (all integer types), `Float` and `Double`.\n\nFor detailed usage examples take a look at [Usage.md](./Docs/Usage.md).\n\n## ToDo\n\nThis framework is production ready but there are still many possible improvements. Some known tasks are:\n\n- Better thread synchronization. The cache uses serial dispatch queues to handle concurrent access and memory/disk value synchronization. This makes the code easy to follow and reason about, but it is not as performant as a solution using the multiple reader single writer pattern. We tried using concurrent dispatch queues with dispatch barriers for cache updates, but it got messy and code readability suffered. In early development serial queues were the way to go, but there is room for improvement.\n- Limit for disk usage. The disk cache has no limit on how much data it stores.\n- Default `DataConvertable` support more common types.\n\nPull requests are very welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrkno%2Fyr-cachyr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrkno%2Fyr-cachyr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrkno%2Fyr-cachyr/lists"}