Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cozzin/cache

💾 Simple memory & disk cache
https://github.com/cozzin/cache

cache disk-cache ios mac memory-cache swift

Last synced: 2 days ago
JSON representation

💾 Simple memory & disk cache

Awesome Lists containing this project

README

        

# Cache

💾 Simple memory & disk cache

## Usage

### 🧑‍💻 Default

```swift
let cache = Cache()

try memory.save("MyValue", forKey: "MyKey")

let cached = try cache.value(forKey: "MyKey")
```

### 🚀 Advanced

You can also use custom object with `Codable`

```swift
struct CustomObject: Codable {
let value: Int
}

let memory = MemoryCache(countLimit: 100)
let disk = DiskCache(fileManager: fileManager)
let cache = Cache(memory: memory, disk: disk)

try cache.save(CustomObject(value: 0), forKey: "MyKey")

let cached = try cache.value(forKey: "MyKey")
```

## ♻️ Flow

### Load value

1. Load memory cache if available
2. Load disk cache if available
2-1. then, save to memory cache if value existed in disk cache

### Save value

1. Save memory & cache

## 🧰 Installation
1. In your Xcode project, navigate to File > Swift Packages > Add Package Dependancy...
2. Paste the following into the URL field: https://github.com/cozzin/Cache