Latest 0.1.0
Homepage https://github.com/ivangodfather/RxLiteCache
License MIT
Platforms ios 8.3
Dependencies RxSwift
Authors

Description

Installation

Example Usage

First create a class that implementes NSCoding and RxLiteCacheable protocols.

class Person: NSObject, NSCoding, RxLiteCacheable {
    let name: String
    init(name: String) { self.name = name }

    func encode(with aCoder: NSCoder) {
        aCoder.encode(name, forKey: "name")
    }

    required init?(coder aDecoder: NSCoder) {
        self.name = aDecoder.decodeObject(forKey: "name") as! String
    }

    var primaryKey: String { return name }
}

Create the cache that will hold those elements

let personCache: RxLiteCache<String, Person> = RxLiteCache(cacheName: "person", 
                                                           cacheTime: RxLiteCacheTime.minutes(5))

Remember in other to create a RxLiteCache<K,T> K must be Hashable and the primary key of T.

Now you are ready to go

let noel = Person(name: "Noel")
let noelFromOtherSource = Person(name: "Noel Gallagher")
personCache.add(firstPerson).subscribe()  //adds first person to cache 
personCache.get("Noel",                    //asks for person with identifier "Noel"
              source: Observable.just(secondPerson))  //in case of failure grabs it elsewhere
    .subscribe(onNext: { print($0.name) })

This will print Noel. If you want to erase the item from the cache then:

personCache.removeKey(hasheable: "Noel")

Getting the idenfitier again will output "Noel Gallagher".

Latest podspec

{
    "name": "RxLiteCache",
    "version": "0.1.0",
    "summary": "RxSwift Cache.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/ivangodfather/RxLiteCache",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ivan Ruiz Monjo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ivangodfather/RxLiteCache.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.3"
    },
    "source_files": "RxLiteCache/**/*",
    "dependencies": {
        "RxSwift": [
            "3.0.0-rc.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This