{"id":13465375,"url":"https://github.com/Sadmansamee/CachyKit","last_synced_at":"2025-03-25T16:31:37.774Z","repository":{"id":54514116,"uuid":"206918912","full_name":"Sadmansamee/CachyKit","owner":"Sadmansamee","description":"A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.","archived":false,"fork":false,"pushed_at":"2021-06-03T02:29:57.000Z","size":251,"stargazers_count":124,"open_issues_count":2,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-02T21:02:02.882Z","etag":null,"topics":["cache","ios","nscache","swift"],"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/Sadmansamee.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":"2019-09-07T05:10:13.000Z","updated_at":"2024-06-25T09:02:39.000Z","dependencies_parsed_at":"2022-08-13T18:20:31.578Z","dependency_job_id":null,"html_url":"https://github.com/Sadmansamee/CachyKit","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sadmansamee%2FCachyKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sadmansamee%2FCachyKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sadmansamee%2FCachyKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sadmansamee%2FCachyKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sadmansamee","download_url":"https://codeload.github.com/Sadmansamee/CachyKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222088540,"owners_count":16928976,"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","ios","nscache","swift"],"created_at":"2024-07-31T15:00:28.623Z","updated_at":"2024-10-29T17:30:47.266Z","avatar_url":"https://github.com/Sadmansamee.png","language":"Swift","funding_links":[],"categories":["Libs","Cache [🔝](#readme)","Data and Storage"],"sub_categories":["Cache"],"readme":"# CachyKit\n[![codebeat badge](https://codebeat.co/badges/de5bf12e-9682-4d1e-85ce-fbc89a738f3d)](https://codebeat.co/projects/github-com-sadmansamee-cachykit-master) ![](https://img.shields.io/cocoapods/v/CachyKit.svg?style=flat)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"400\"  src=\"cachy.png\"\u003e\n\u003c/p\u003e\n\n## Description\n \nNice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.\n\n## Installation\n\n### Cocoapods\n\n[**CachyKit**](http://cocoapods.org/pods/CachyKit) is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile: \n\n```ruby\npod 'CachyKit'\n```\nthen run \n\n```\n$ pod repo update\n```\n```\n$ pod install\n```\n\n## Features\n\n- [x] Asynchronous data downloading and caching.\n- [x] Asynchronous image downloading, caching and showing.\n- [x] Expiry date/time for all the object individually.\n- [x] Multiple-layer hybrid cache for both memory and disk.\n- [x] Fine control on cache behavior. Customizable expiration date and size limit.\n- [x] Force refresh if needed.\n- [x] Independent components. Use the [Cachy](https://github.com/Sadmansamee/CachyKit/blob/master/Sources/Cachy/Cachy.swift) or [CachyLoader](https://github.com/Sadmansamee/CachyKit/blob/master/Sources/Cachy/CachyLoader.swift) system separately as you need.\n- [x] Can save JSON, UIImage, ZIP or AnyObject.\n- [x] View extensions for `UIImageView`.\n- [x] Indicator while loading images.\n\n\n## Usage\n\n```swift\nimport CachyKit\n```\n\nIf you want to download and cache a file(JSON, ZIP, UIImage or any type) then simply call with a url\n\n```swift\n let cachy = CachyLoader()\n\n cachy.loadWithURL(URL(string: \"http://your_url_here\")!) { [weak self] data, _ in\n    // Do whatever you need with the data object\n }\n```\n\nYou can also cache with **URLRequest**\n\n```swift\nlet cachy = CachyLoader()\n\nlet request = URLRequest(url: URL(string: \"http://your_url_here\")!)\ncachy.loadWithURLRequest(request) { [weak self] data, _ in\n    // Do whatever you need with the data object\n }\n```\n\nif you want set expiry date for each object \n\n```swift\nlet cachy = CachyLoader()\n\n//(optional) if isRefresh = true it will forcefully refresh data from remote server\n//(optional) you can set **expirationDate** according to your need\n\ncachy.loadWithURL(URL(string: \"http://your_url_here\")!,isRefresh = false,expirationDate = ExpiryDate.everyDay.expiryDate()) { [weak self] data, _ in\n     // Do whatever you need with the data object\n  }\n```\n\n**Clear** all cache\n\n```swift\nCachyLoaderManager.shared.clear()\n```\n\n**CachyLoader** has also UIImageView extension.\n\n```swift\n//(optional) if isShowLoading is true it will show a loading indicator\nimageView.cachyImageLoad(\"your URL\", isShowLoading: true, completionBlock: { _, _ in })\n```\n\nIt will download, cache and load UIImage into your UIImageView\n**CachyLoader** is also configurable, by calling function ***CachyLoaderManager.shared.configure()***\n\n```swift\n// All the parametre is optional\n// Here if you want set how much much memory/disk should use set memoryCapacity, diskCapacity\n// To cache only on memory set isOnlyInMemory which is true by default\n// You may set expiry date for all the cache object by setting expiryDate\n// Your objects may not be conforming to `NSSecureCoding`, set this variable to `false`\n\nCachyLoaderManager.shared.configure(\n     memoryCapacity: 1020,\n     maxConcurrentOperationCount: 10,\n     timeoutIntervalForRequest: 3,\n     expiryDate: ExpiryDate.everyWeek,\n     isOnlyInMemory: true,\n     isSupportingSecureCodingSaving: false\n)\n```\n\n**expiryDate** parametre takes\n\n1. **.never** to never expire the cache object\n2. **.everyDay** to expire at the end of the day\n3. **.everyWeek** to expiry after a week\n4. **.everyMonth** to set the expiry date each month\n5. **.seconds** to set the expiry after some seconds \n\n\n## Without CachyLoader\n\nTo cache using **CachyLoader** is the easiest way to do, but if you want manage your caching, sycning and threading **CachyKit** also supports that.\n\n### Configuration\n\nHere is how you can setup some configuration options\n\n```swift\nCachy.countLimit = 1000 // setup total count of elements saved into the cache\n\nCachy.totalCostLimit = 1024 * 1024 // setup the cost limit of the cache\n\nCachy.shared.expiration = .everyDay // setup expiration date of each object in the cache\n\nCachy.shared.isOnlyInMemory = false // will be cached on Memory only or both\n\n```\n\n\n### Adding/Fetching objects\n\nIf you want to add or fetch an object you just follow these simple steps:\n\n```swift\n//1. Create a CachyObject\nlet object = CachyObject(value: \"HEllo, Worlds\", key: \"key\")\n\n// A given expiry date will be applied to the item\nlet object2 = CachyObject(value: \"HEllo, Worlds\", key: \"key\",expirationDate: ExpiryDate.everyDay.expiryDate())\n\n//2. Add it to the cache\nCachy.shared.add(object: object)\n\n//3. Fetch an object from the cache\nlet string: String? = Cachy.shared.get(forKey: \"key\")\n```\n\n## Contact\n\nFollow and contact me on [Twitter](https://twitter.com/SameeSadman) or [LinkedIn](https://www.linkedin.com/in/sadmansamee/). If you find an issue, just [open a ticket](https://github.com/sadmansamee/Cachy/issues/new). Pull requests are warmly welcome as well.\n\n## Contribution\n\nIf you want fix anything or improve or add any new feature you are very much welcome.\n\n### License\n\nCachy is released under the MIT license. See LICENSE for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSadmansamee%2FCachyKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSadmansamee%2FCachyKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSadmansamee%2FCachyKit/lists"}