Swiftpack.co - modernistik/MemoryJar as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by modernistik.
modernistik/MemoryJar 0.3.0
Fast, efficient, and thread-safe API LRU caching for Swift
⭐️ 3
🕓 1 year ago
iOS tvOS
.package(url: "https://github.com/modernistik/MemoryJar.git", from: "0.3.0")

MemoryJar

MemoryJar is a fast and efficient and thread-safe persistent string caching library that includes capacity management (LRU) and support for age expiration. It utilizes both in-memory and disk storage, supporting asynchronous writes for speed. This library was inspired by the caching mechanism on the Parse iOS SDK.

This caching library is most useful when building a caching system for managing a REST API.

CI Status Version License Platform

Installation

To install it, simply add the following line to your Podfile:

pod "MemoryJar"

Usage

import MemoryJar

// use shared, or create your own with MemoryJar()
let cache = MemoryJar.shared

// Simple
cache["company"] = "Modernistik"
// retrieve (no expiration)
let company = cache["company"]

// Some API response
let json = """
{
    "name" : "Anthony Persaud",
    "id" : 7,
    "company" : {
        "name" : "Modernistik",
        "location": "San Diego, CA"
     }
}
"""

let cacheKey = "https://some.api/?id=7"

// set the value
cache.set(value: json, forKey: cacheKey)

// fetch value only if it is not older than 1 day.
if let result = cache.get(forKey: cacheKey, maxAge: 86400) {
    print(result)
}

// deletes all cache objects
cache.removeAllObjects()

Todo

  • Support clearing specific url paths matching a pattern.

Author

Anthony Persaud, https://www.modernistik.com

License

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

GitHub

link
Stars: 3
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics