Giter VIP home page Giter VIP logo

cacher's Introduction

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

cacher's People

Contributors

benemdon avatar dvlprliu avatar kraw-ios avatar raulriera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cacher's Issues

Cocoa pods support

I tried implementing the podspec, but couldn't get it to build due to Xcode 9 incompatibility or lack of multi platform support from cocoa pods? If you have tips, PR are welcome

Cache files get deleted after new run

@raulriera Hello,

Cache files are deleted after the application is run again, but during application execution it is able to get the cache properly from the directory.

Do you know what it can be? because it’s strange that he’s able to fetch during runtime, but if I close and open the app again, he cannot.

Thanks

Release with SPM support

Please make a release from the latest master, it's ready to support SPM but latest release is 1.2.1 from Sept 2017...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.