All Projects → onmyway133 → Easystash

onmyway133 / Easystash

Licence: other
🗳Easy data persistence in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Easystash

QuickDB
A Generic CoreData Manager to accept any type of objects. Fastest way for adding a Database to your project.
Stars: ✭ 16 (-94.72%)
Mutual labels:  storage, codable
infinitree
Scalable and encrypted embedded database with 3-tier caching
Stars: ✭ 80 (-73.6%)
Mutual labels:  storage, cache
PSDiskPart
DiskPart PowerShell Module
Stars: ✭ 30 (-90.1%)
Mutual labels:  disk, storage
Caching
⏱ Caching library with easy-to-use API and many cache backends.
Stars: ✭ 234 (-22.77%)
Mutual labels:  cache, storage
stash
A Go package for disk-based blob cache
Stars: ✭ 14 (-95.38%)
Mutual labels:  disk, cache
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (-16.5%)
Mutual labels:  cache, storage
storage-box
Intuitive and easy-to-use storage box.
Stars: ✭ 26 (-91.42%)
Mutual labels:  storage, cache
Jstarcraft Core
目标是提供一个通用的Java核心编程框架,作为搭建其它框架或者项目的基础. 让相关领域的研发人员能够专注高层设计而不用关注底层实现. 涵盖了缓存,存储,编解码,资源,脚本,监控,通讯,事件,事务9个方面.
Stars: ✭ 150 (-50.5%)
Mutual labels:  cache, storage
DTC
DTC is a high performance Distributed Table Cache system designed by JD.com that offering hotspot data cache for databases in order to reduce pressure of database and improve QPS.
Stars: ✭ 21 (-93.07%)
Mutual labels:  storage, cache
elara
Elara DB is an easy to use, lightweight key-value database that can also be used as a fast in-memory cache. Manipulate data structures in-memory, encrypt database files and export data. 🎯
Stars: ✭ 93 (-69.31%)
Mutual labels:  storage, cache
Sjnetwork
SJNetwork is a high level network request tool based on AFNetworking and inspired on YTKNetwork.
Stars: ✭ 231 (-23.76%)
Mutual labels:  cache, image
Storage
An iOS library for fast, easy, and safe threaded disk I/O.
Stars: ✭ 259 (-14.52%)
Mutual labels:  storage, disk
Torchdata
PyTorch dataset extended with map, cache etc. (tensorflow.data like)
Stars: ✭ 226 (-25.41%)
Mutual labels:  cache, disk
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (-92.41%)
Mutual labels:  disk, storage
Recent Images
Do you noticed the new feature of Telegram or Instagram?! They show your latest images when you try to attach or post a picture. So I developed this library the same with lots of customization. Simple way to get all images of device based on date taken, name, id and other customization
Stars: ✭ 182 (-39.93%)
Mutual labels:  cache, image
CodablePersist
Store and Cache Anything Codable
Stars: ✭ 18 (-94.06%)
Mutual labels:  storage, codable
Cash
HTTP response caching for Koa. Supports Redis, in-memory store, and more!
Stars: ✭ 122 (-59.74%)
Mutual labels:  cache, storage
Bbwebimage
A high performance Swift library for downloading, caching and editing web images asynchronously.
Stars: ✭ 128 (-57.76%)
Mutual labels:  cache, image
incache
Powerful key/value in-memory storage or on disk to persist data
Stars: ✭ 16 (-94.72%)
Mutual labels:  storage, cache
lethe
Secure drive wipe
Stars: ✭ 47 (-84.49%)
Mutual labels:  disk, storage

❤️ Support my apps ❤️

❤️❤️😇😍🤘❤️❤️

CI Status Version Carthage Compatible SPM compatible License Platform Swift

Description

EasyStash is an easy and lightweight persistence framework in Swift. With simple abstraction over NSCache and FileManager, it saves us from tedious work of saving and loading objects. There are no clever async, expiry handling or caching strategy for now, just save and load.

  • [x] Swift 5
  • [x] Support iOS, macOS, tvOS, watchOS
  • [x] Synchronous APIs with explicit try catch
  • [x] Persist UIImage/NSImage
  • [x] Persist Codable objects, including primitive types
  • [x] Persist Data
  • [x] Test coverage

Usage

The main and only class is Storage which encapsulates memory and disk cache. All operations involving disk are error prone, we need to handle error explicitly.

With Options, we can customize folder name, searchPathDirectory, encoder and decoder for Codable. By default, folder and searchPathDirectory specify that files will be saved at /Library/Application Support/{BUNDLE_ID}/Default/

var storage: Storage? = nil

var options: Options = Options()
options.folder = "Users"

storage = try? Storage(options: options)

do {
    try storage?.save(image, forKey: "image")
    try storage?.save(users, forKey: "codable")
} catch {
    print(error)
}

Memory cache is checked first before doing disk operations, so we won't hit disk that often.

Saving and loading images

Works for both UIImage and NSImage. Because image and data loading uses the same signatures, we need to explicitly specify type

try storage.save(image, forKey: "image")
let loadedImage: UIImage = try storage.load(forKey: "image")

Saving and loading Codable objects

Uses JSONEncoder and JSONDecoder under the hood to serialize and deserialize to and from Data

let user = User(name: "A", age: 10)
let cities = [City(name: "Oslo"), City(name: "New York")]

try storage.save(users, forKey: "user")
try storage.save(cities, forKey: "cities")

let loadedUser = try storage.load(forKey: "user", as: User.self)
let loadedCities = try storage.load(forKey: "cities", as: [City].self)

Saving and loading Data

try storage.save(object: data, forKey: "data")
let loadedData: Data = try storage.load(forKey: "data")

Saving and loading primitives

Although primitives like Int, String, Bool conform to Codable, they can't be serialized into Data using JSONEncoder because json needs root object. This framework handles this case, so you can just save and load as normal

try storage.save(100, forKey: "an int")
try storage.save(isLoggedIn, forKey: "a boolean")

Folder informations

EasyStash includes some helpful functions to check file and folder within its Storage.

Check if file exists

try storage.exists(forKey: "has_updated_profile")

Remove file

try storage.remove(forKey: "a flag")

Remove all files

try storage.removeAll()

List all files. Each file has name, url, modificationDate and size information

let files = try storage.files()

Check folder size

let size = try storage.folderSize()

Check if folder has content

try storage.isEmpty()

Remove files based on predicate. This is useful when we want to clear expired objects, or objects based certain criteria.

try storage.removeAll(predicate: { $0.modificationDate < migrationDate })

Async

EasyStash is designed to be synchronous. If we want to do async, it's easy as using DispatchQueue

DispatchQueue.global().async {
    do {
        try storage.save(largeImage, forKey: "large_image")
    } catch {

    }
}

Installation

EasyStash is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EasyStash'

EasyStash is also available through Carthage. To install just write into your Cartfile:

github "onmyway133/EasyStash"

EasyStash is also available through Swift Package Manager. Add EasyStash as a dependency to your Package.swift. For more information, please see the Swift Package Manager documentation.

.package(url: "https://github.com/onmyway133/EasyStash", from: "1.1.8")

EasyStash can also be installed manually. Just download and drop Sources folders in your project.

Author

Khoa Pham, [email protected]

Contributing

We would love you to contribute to EasyStash, check the CONTRIBUTING file for more info.

License

EasyStash is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].