Skip to content

Thread safe on disk persistence manager with Codable and backed by NSCache.

License

Notifications You must be signed in to change notification settings

nikksindia/SwifteeCache

Repository files navigation

SwifteeCache

Simple on disk cache, backed by an NSCache in memory. It automatically purges itself when memory gets low.

Swift Version Platform License Build Status PRs Welcome swift-package-manager Carthage compatible CocoaPods Compatible

Features

  • Support all data types confirming to Codable protocol
  • Thread safe and optmised for fater caching
  • Objects can be purged in case of low memory in the system

Requirements

  • iOS 10.0+
  • Xcode 9+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SwifteeCache into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '10.0'
use_frameworks!
pod 'SwifteeCache'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/SwifteeCache.framework to an iOS project.

github "nikksindia/SwifteeCache"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding SwifteeCache as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/nikksindia/SwifteeCache.git", .upToNextMajor(from: "1.1.0"))
]

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate SwifteeCache into your project manually.

  1. Download and drop SwifteeCache.swift in your project.
  2. Congratulations!

Usage

For adding/removing objects in cache:

func setObject<T:Codable>(_ object:T,forKey key:String)
func removeObjectForKey(_ key:String)
func removeAllObjects()

For fetching objects in cache:

func getObjectForKey<T:Codable>(_ key:String)->T?
func objectExistsForKey(_ key:String)->Bool

Sample application

Build and run the Example target. This is a simple implementation of the library that allows users to select fetch and store codable mock data in the cache.

Testing

The project includes a unit test and UI test target, providing coverage of the basic layout and functionality of the product. When adding a new feature, be sure to add unit tests and a basic layout test if applicable.

Contribute

We would love you for the contribution to SwifteeCache, check the LICENSE file for more info.

Meta

Nikhil Sharma – @devilnikksnikksindia@gmail.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/nikksindia