• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 Repositories

1

Sofie-TV-automation

The Sofie TV Studio Automation System, used in live TV news production by the Norwegian public service broadcaster NRK since September 2018
310
star
2

sofie-atem-connection

Sofie ATEM Connection: A Part of the Sofie TV Studio Automation System
TypeScript
128
star
3

sofie-core

Sofie Core: A Part of the Sofie TV Studio Automation System
TypeScript
124
star
4

yr-weather-symbols

Weather symbols for yr.no
TypeScript
121
star
5

core-components

Accessible and lightweight Javascript components
TypeScript
117
star
6

terraform-registry

A private Terraform registry with modular store backends.
Go
88
star
7

terraform-provider-lastpass

Terraform Lastpass provider
Go
61
star
8

Tumbleweed

Logs detailed metrics about NSURLSession tasks to the console
Swift
51
star
9

Quibble

JSON diff tool for .NET
C#
45
star
10

Quibble.Xunit

XUnit-like asserts for text strings with JSON content.
F#
40
star
11

samnorsk

Elastic support for Bokmål/Nynorsk
Scala
32
star
12

transcriber-frontend

TypeScript
32
star
13

nativebridge

Lightweight and efficient bridge between webview and native app
JavaScript
26
star
14

sofie-casparcg-launcher

Sofie CasparCG Launcer: A Part of the Sofie TV Studio Automation System
JavaScript
24
star
15

sofie-mos-connection

Sofie MOS Connection: A Part of the Sofie TV Studio Automation System
TypeScript
22
star
16

yaml-schema-validator-github-action

A GitHub action that uses Yamale for YAML schema validation
Shell
20
star
17

nodecache-as-promised

In-memory cache supporting promise based workers and middleware hooks (distributed expiry and persistence provided)
JavaScript
20
star
18

Eventually

A Swift Future/Promise library that can be used to model and transform asynchronous results
Swift
19
star
19

dotnetskolen

Kurs for oppsett av .NET-prosjekter fra bunn
18
star
20

sofie-playout-gateway

Sofie: The Modern TV News Studio Automation System (Playout Gateway)
TypeScript
18
star
21

postcss-classes-to-mixins

Intelligently convert CSS classes to SASS, Less and Stylus mixins
JavaScript
14
star
22

core-icons

Core icons for web services and native apps.
Kotlin
14
star
23

nrkno-sanity-libs

Monorepo for open source libraries used by nrkno-sanity
TypeScript
14
star
24

sofie-timeline-state-resolver

Sofie Timeline State Resolver: A Part of the Sofie TV Studio Automation System
TypeScript
14
star
25

odashboard

A configurable dashboard with a simple plugin architecture
JavaScript
13
star
26

core-css

Core CSS layer for web services.
CSS
13
star
27

sofie-atem-state

Sofie ATEM State: A Part of the Sofie TV Studio Automation System
TypeScript
11
star
28

doobie-postgres-migration

Schema migrations for Postgresql built with doobie
Scala
10
star
29

MMM-Slack

Slack integration for MagicMirror²
JavaScript
10
star
30

expect-openapi

Expect matchers for OpenApi responses
TypeScript
9
star
31

Nrk.HttpRequester

Library for sending Http Requests, including a fluent interface for creating HttpClient instances
C#
8
star
32

simple-date-parse

Super lightweight simple natural language date parsing in javascript
JavaScript
7
star
33

prog-intro

Introduksjonskurs i programmering
Python
7
star
34

sofie-mos-gateway

Sofie: The Modern TV News Studio Automation System (MOS Gateway)
TypeScript
7
star
35

sorensen

A modern, i18n-friendly hotkey library for the Web
TypeScript
7
star
36

arkivpublisering.nrk.no

JavaScript
7
star
37

yr-time

An efficient, immutable, utility for working with time/dates.
JavaScript
6
star
38

nativebridge-android

Android library for Native Bridge. A lightweight and efficient bridge between webview and native apps.
Kotlin
6
star
39

transcriber-backend

TypeScript
6
star
40

sofie-chef

Sofie Chef: A Part of the Sofie TV Studio Automation System
TypeScript
6
star
41

svg-to-js

Module for concatenating SVG files into JavaScript
JavaScript
6
star
42

nativebridge-ios

Lightweight and efficient bridge between webview and native app (iOS connector)
Swift
5
star
43

custom-element-to-react

Converts a custom element to a React component, with props and events.
JavaScript
5
star
44

valg-valgomat-algoritme

The algorithm used to calculate distance between sets of positions for NRKs Valgomat
JavaScript
5
star
45

terraform-provider-windns

Manage DNS records in a Windows DNS Servers using Terraform
Go
5
star
46

sofie-hyperdeck-connection

Sofie HyperDeck Connection: A Part of the Sofie TV Studio Automation System
TypeScript
5
star
47

core-docs

Write documentation in markdown and render it beautifully
JavaScript
4
star
48

github-workflow-semantic-release

Semantic Release workflow through github action
JavaScript
4
star
49

bigquery-scala

Bigquery library for scala
Scala
4
star
50

github-workflow-docker-build-push

Dockerfile
4
star
51

nrk-sans-styles

Definitions of the font styles of NRK Sans.
Swift
4
star
52

best-practice

Best practice guide to (at start) programming native apps in NRK
4
star
53

fsharpskolen

F#
4
star
54

wave-bwf-rf64

Extension of Pythons Wave-library to support BWF and RF64
Python
4
star
55

github-workflow-terraform-config

Reusable GitHub workflow for validating a Terraform configuration repository.
HCL
4
star
56

sofie-core-integration

Sofie: The Modern TV News Studio Automation System (Server Core Integration library)
TypeScript
3
star
57

sofie-quantel-gateway

Sofie Quantel Gateway: A Part of the Sofie TV Studio Automation System
C++
3
star
58

prog-videre

Programmeringskurs for viderekomne
Python
3
star
59

sofie-media-management

Sofie: The Modern TV News Studio Automation System (Media Manager)
TypeScript
3
star
60

sofie-blueprints-integration

Sofie: The Modern TV News Studio Automation System (Sofie Blueprints Integration library)
TypeScript
3
star
61

sofie-package-manager

Sofie Package Manager: A Media Asset Manager. A Part of the Sofie TV Studio Automation System
TypeScript
2
star
62

akamai-datastream-influxdb

Kubernetes application to read aggregated akamai datastreams and send them to influxdb (archived)
Python
2
star
63

rfetch

Isomorphic fetch with retry
JavaScript
2
star
64

sofie-cutout-tool

Sofie: The Modern TV News Studio Automation System (A tool to define cutouts/crops from live video sources.)
JavaScript
2
star
65

sofie-e2e-test-runner

Sofie End-to-end Test Runner and Report Browser: A Part of the Sofie TV Studio Automation System
TypeScript
2
star
66

sofie-sony-visca-connection

Sofie: The Modern TV News Studio Automation System (Sony Visca Connection)
TypeScript
2
star
67

den-mangfoldige-mobben

1
star
68

lydteam-kubernetes-sandbox

Sandbox for testing/learning kubernetes
Shell
1
star
69

sofie-lawo-state

This repo is deprecated due to it never being used by the authors, and therefore no longer maintained.
TypeScript
1
star
70

halite

C#
1
star
71

brainfuck_programmer

Her ligger kode fra innovasjonsdagene i september 2021 hvor vi tenkte stort og prøvde å lage en algoritme som kunne programmere i Brainfuck.
PowerShell
1
star
72

transcriber-cli

Command line tool for interacting with Transcriber Backend
TypeScript
1
star
73

mellomvare-radio-MDW2

Metadatatjeneste for "hva-spilles-nå"
Python
1
star
74

nrk-shared-java

NRK Shared Java libraries
Java
1
star
75

sofie-prompter-editor

Sofie Prompter Editor: A Part of the Sofie TV Studio Automation System
TypeScript
1
star
76

yr-warning-icons

JavaScript
1
star
77

sofie-quantel-browser-plugin

Sofie Quantel Browser Plugin: A Part of the Sofie TV Studio Automation System
JavaScript
1
star
78

netbox-devicetype-library

Python
1
star