• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Super simple caching solution for iOS, macOS, tvOS and watchOS.

Build Status

For a detail information about using "Cacher", checkout the article "Caching anything in iOS".

Installation

Manual

Drag and drop the Cacher/ folder into your project.

Carthage

Add the following to your Cartfile:

github "raulriera/Cacher"

Swift Package Manager

Add this repo to your dependencies.

How to use them

For a quick TL;DR check out the sample project at CacherDemo. It will guide you with the simplest caching possible, persisting string values.

If you like to get your hands dirty, continue reading as we are going to go into detail about how this works.

public protocol Cachable {
	var fileName: String { get }
	func transform() -> Data
}

It all comes down to this simple protocol, that has only two requirements fileName which represents the unique name to store in the filesystem, and transform which is the Data representation of what you wish to import. Using the magic of Swift 4 Codable, we can skip the transform implementation and use the implicit one declared right here.

After we implement conform to Cachable and Codable, anything can be stored in the filesystem using the persist:item:completion method.

But, let's see a more complex example

struct CachableMovies: Cachable, Codable {
	let store: String
	let movies: [Movie]

	var fileName: String {
		return "movies-\(store)"
	}

	init(store: String, movies: [Movie]) {
		self.store = store
		self.movies = movies
	}
}

struct Movie: Codable {
  enum CodingKeys : String, CodingKey {
  		case title = "movie_title"
  		case description = "movie_description"
  		case url = "movie_url"
  }

  let title: String
  let description: String
  let url: URL
}

The previous code is all we need to store a collection of movies into the filesystem. 🎉 Now we can simply use the persist method like this.

Cacher(destination: .temporary).persist(item: CachableMovies(store: "USA", movies: myArrayOfMovies)) { url, error in
	// Completion handler when the process finishes
}

Created by

Raul Riera, @raulriera

More Repositories

1

TextFieldEffects

Custom UITextFields effects inspired by Codrops, built using Swift
Swift
5,952
star
2

AuthenticationViewController

A simple to use, standard interface for authenticating to oauth 2.0 protected endpoints via SFSafariViewController.
Swift
257
star
3

Bike-Compass

iOS and  Watch app to find city bicycles to rent in your city
Swift
83
star
4

Animator

Animator helper class for Titanium Appcelerator.
JavaScript
58
star
5

Titanium-Booker

Titanium port of the wonderful Laker Compendium
JavaScript
53
star
6

UpvoteControl

UIControl for up vote widgets found in Product Hunt and Reddit
Swift
52
star
7

Instagram-For-iPad

Instagram client for iPad. Built using Titanium Alloy from Appcelerator
JavaScript
44
star
8

HuntingKit

Wrapper for the ProductHunt API. Written in Swift
Swift
44
star
9

alloy-widgets

Repository of my Titanium Alloy Widgets
JavaScript
30
star
10

Rater-Module

Create a cycling reminder to go rate your app at the App Store.
JavaScript
28
star
11

technical-articles

Just a place where I can store demo projects for my technical articles.
Swift
27
star
12

InfiniteTableView

A cross platform infinite tableview very similar to Instagram built using Appcelerator Titanium
CoffeeScript
21
star
13

ImageGalleryView

Multiplatform ImageGalleryView for Titanium Appcelerator
CoffeeScript
19
star
14

Remote-Form-Helpers

AJAX Form Helpers for ColdFusion on Wheels
ColdFusion
14
star
15

ForecastView

Extensible View subclass that displays the weather forecast of a given CLLocationCoordinate2D. Written in Swift ❤️
Swift
14
star
16

ColdFusion-Sugar

ColdFusion Sugar for MacRabbit's Espresso
13
star
17

MemPool-Module

MemPool is a module created to simplify the debugging of application performance in Appcelerator's Titanium
JavaScript
11
star
18

Scaffold

Scaffold plugin for ColdFusion on Wheels
ColdFusion
11
star
19

ghost-storage-supabase

Supabase storage adapter for Ghost. Recommended as a completely free storage solution for blogs being hosted on platforms with ephemeral filesystems, like Heroku.
JavaScript
10
star
20

probot-minimum-reviews

enforce a minimum number of reviews on Pull Requests
JavaScript
10
star
21

react-native-window-tint-color

React Native Module to globally tint the keyWindow in an iOS application
Java
9
star
22

Overlay-HUD

A simple Overlay HUD Module for Titanium following CommonJS best practices
JavaScript
8
star
23

WTFamous-App

Titanium Appcelerator application mimicking a magic 8 ball game with famous characters
JavaScript
8
star
24

Localizer

Localizer plugin for ColdFusion on Wheels
ColdFusion
7
star
25

HuntingCompanion

ProductHunt example app using Swift and the HuntingKit framework.
Swift
6
star
26

probot-duplicator

Create full copies of issues with a single command
JavaScript
6
star
27

EmojiStickers

Everything http://www.raulriera.com/emoji
Swift
6
star
28

Transactional-Email-Designer

Responsive transactional HTML email designer
JavaScript
6
star
29

BlankStateViewController

Convenience view controller to hide content on errors, present a loading message or simply have something there if you have nothing else to display
Objective-C
4
star
30

PillLabel

UILabel subclass with support for border color, border radius and padding. All accesible via de Inspector window
Objective-C
4
star
31

LoadingButton

Dead simple UIButton with a companion UIActivityIndicator written in Swift
Swift
3
star
32

Antitabaco-App

Small iOS application to report any establishment not following the anti tobacco law in Spain
JavaScript
3
star
33

Mobile-Helpers

Mobile Helper functions for ColdFusion on Wheels
1
star
34

Bootstrap-Dropdown-Extension

Easily enable content switching in a Bootstrap dropdown
JavaScript
1
star