Skip to content

cozzin/Cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cache

๐Ÿ’พ Simple memory & disk cache

Usage

๐Ÿง‘โ€๐Ÿ’ป Default

let cache = Cache<String>()

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

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

๐Ÿš€ Advanced

You can also use custom object with Codable

struct CustomObject: Codable {
    let value: Int
}

let memory = MemoryCache<CustomObject>(countLimit: 100)
let disk = DiskCache<CustomObject>(fileManager: fileManager)
let cache = Cache<CustomObject>(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

About

๐Ÿ’พ Simple memory & disk cache

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages