ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - nrkno/yr-cachyr: A small key-value data cache for iOS, macOS and tvOS, written in Swift.
A small key-value data cache for iOS, macOS and tvOS, written in Swift. - nrkno/yr-cachyr
Visit Site

GitHub - nrkno/yr-cachyr: A small key-value data cache for iOS, macOS and tvOS, written in Swift.

GitHub - nrkno/yr-cachyr: A small key-value data cache for iOS, macOS and tvOS, written in Swift.

Cachyr

A typesafe key-value data cache for iOS, macOS, tvOS and watchOS written in Swift.

There 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:

  • Written purely in Swift 3.
  • Type safety while still allowing any kind of data to be stored.
  • Disk and memory caching.
  • Easy way to populate cache when a lookup results in a cache miss.
  • Clean, single-purpose implementation. Do caching and nothing else.

Installation

CocoaPods

Add to Podfile:
pod 'Cachyr'

Then:
$ pod install

Swift Package Manager

The Swift 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.

To integrate Cachyr into your Xcode project using Xcode 11, specify it in File > Swift Packages > Add:

https://github.com/nrkno/yr-cachyr

Manual

Clone the repo somewhere suitable, like inside your project repo so Cachyr can be added as a subrepo, then drag Cachyr.xcodeproj into your project.

Alternatively build the framework and add it to your project.

Usage

let cache = DataCache()
let key = "foo"
let text = "bar"
cache.setValue(text, for: key)

// ... do important things ...

let cachedText: String? = cache.value(for: key)

// Or asynchronously
let cachedText = cache.value(for: key) { (value: String?) in
    // Do something with value
}

In 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.

let textAsData = cache.value(for: key) { (value: Data?) in
    print(value)
}

Now 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.

There are default DataConvertable implementations for Data, String, Int (all integer types), Float and Double.

For detailed usage examples take a look at Usage.md.

ToDo

This framework is production ready but there are still many possible improvements. Some known tasks are:

  • 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.
  • Limit for disk usage. The disk cache has no limit on how much data it stores.
  • Default DataConvertable support more common types.

Pull requests are very welcome.

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