ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - Sadmansamee/CachyKit: A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.
A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh. - Sadmansamee/CachyKit
Visit Site

GitHub - Sadmansamee/CachyKit: A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

GitHub - Sadmansamee/CachyKit: A Caching Library is written in Swift that can cache JSON, Image, Zip or AnyObject with expiry date/TTYL and force refresh.

CachyKit

codebeat badge

Description

Nice threadsafe expirable cache management that can cache any object. Supports fetching from server, single object expire date, UIImageView loading etc.

Installation

Cocoapods

CachyKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CachyKit'

then run

$ pod repo update
$ pod install

Features

  • Asynchronous data downloading and caching.
  • Asynchronous image downloading, caching and showing.
  • Expiry date/time for all the object individually.
  • Multiple-layer hybrid cache for both memory and disk.
  • Fine control on cache behavior. Customizable expiration date and size limit.
  • Force refresh if needed.
  • Independent components. Use the Cachy or CachyLoader system separately as you need.
  • Can save JSON, UIImage, ZIP or AnyObject.
  • View extensions for UIImageView.
  • Indicator while loading images.

Usage

import CachyKit

If you want to download and cache a file(JSON, ZIP, UIImage or any type) then simply call with a url

 let cachy = CachyLoader()

 cachy.loadWithURL(URL(string: "http://your_url_here")!) { [weak self] data, _ in
    // Do whatever you need with the data object
 }

You can also cache with URLRequest

let cachy = CachyLoader()

let request = URLRequest(url: URL(string: "http://your_url_here")!)
cachy.loadWithURLRequest(request) { [weak self] data, _ in
    // Do whatever you need with the data object
 }

if you want set expiry date for each object

let cachy = CachyLoader()

//(optional) if isRefresh = true it will forcefully refresh data from remote server
//(optional) you can set **expirationDate** according to your need

cachy.loadWithURL(URL(string: "http://your_url_here")!,isRefresh = false,expirationDate = ExpiryDate.everyDay.expiryDate()) { [weak self] data, _ in
     // Do whatever you need with the data object
  }

Clear all cache

CachyLoaderManager.shared.clear()

CachyLoader has also UIImageView extension.

//(optional) if isShowLoading is true it will show a loading indicator
imageView.cachyImageLoad("your URL", isShowLoading: true, completionBlock: { _, _ in })

It will download, cache and load UIImage into your UIImageView CachyLoader is also configurable, by calling function CachyLoaderManager.shared.configure()

// All the parametre is optional
// Here if you want set how much much memory/disk should use set memoryCapacity, diskCapacity
// To cache only on memory set isOnlyInMemory which is true by default
// You may set expiry date for all the cache object by setting expiryDate
// Your objects may not be conforming to `NSSecureCoding`, set this variable to `false`

CachyLoaderManager.shared.configure(
     memoryCapacity: 1020,
     maxConcurrentOperationCount: 10,
     timeoutIntervalForRequest: 3,
     expiryDate: ExpiryDate.everyWeek,
     isOnlyInMemory: true,
     isSupportingSecureCodingSaving: false
)

expiryDate parametre takes

  1. .never to never expire the cache object
  2. .everyDay to expire at the end of the day
  3. .everyWeek to expiry after a week
  4. .everyMonth to set the expiry date each month
  5. .seconds to set the expiry after some seconds

Without CachyLoader

To cache using CachyLoader is the easiest way to do, but if you want manage your caching, sycning and threading CachyKit also supports that.

Configuration

Here is how you can setup some configuration options

Cachy.countLimit = 1000 // setup total count of elements saved into the cache

Cachy.totalCostLimit = 1024 * 1024 // setup the cost limit of the cache

Cachy.shared.expiration = .everyDay // setup expiration date of each object in the cache

Cachy.shared.isOnlyInMemory = false // will be cached on Memory only or both

Adding/Fetching objects

If you want to add or fetch an object you just follow these simple steps:

//1. Create a CachyObject
let object = CachyObject(value: "HEllo, Worlds", key: "key")

// A given expiry date will be applied to the item
let object2 = CachyObject(value: "HEllo, Worlds", key: "key",expirationDate: ExpiryDate.everyDay.expiryDate())

//2. Add it to the cache
Cachy.shared.add(object: object)

//3. Fetch an object from the cache
let string: String? = Cachy.shared.get(forKey: "key")

Contact

Follow and contact me on Twitter or LinkedIn. If you find an issue, just open a ticket. Pull requests are warmly welcome as well.

Contribution

If you want fix anything or improve or add any new feature you are very much welcome.

License

Cachy is released under the MIT license. See LICENSE for details.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory